/* * arccosh(x) == log [ x + sqrt(x^2 - 1) ] * * x >= 1.0 */ void m_apm_arccosh(M_APM rr, int places, M_APM aa) { M_APM tmp1, tmp2; int ii; ii = m_apm_compare(aa, MM_One); if (ii == -1) /* x < 1 */ { M_apm_log_error_msg(M_APM_RETURN, "\'m_apm_arccosh\', Argument < 1"); M_set_to_zero(rr); return; } tmp1 = M_get_stack_var(); tmp2 = M_get_stack_var(); m_apm_multiply(tmp1, aa, aa); m_apm_subtract(tmp2, tmp1, MM_One); m_apm_sqrt(tmp1, (places + 6), tmp2); m_apm_add(tmp2, aa, tmp1); m_apm_log(rr, places, tmp2); M_restore_stack(2); }
/* * arcsinh(x) == log [ x + sqrt(x^2 + 1) ] * * also, use arcsinh(-x) == -arcsinh(x) */ void m_apm_arcsinh(M_APM rr, int places, M_APM aa) { M_APM tmp0, tmp1, tmp2; /* result is 0 if input is 0 */ if (aa->m_apm_sign == 0) { M_set_to_zero(rr); return; } tmp0 = M_get_stack_var(); tmp1 = M_get_stack_var(); tmp2 = M_get_stack_var(); m_apm_absolute_value(tmp0, aa); m_apm_multiply(tmp1, tmp0, tmp0); m_apm_add(tmp2, tmp1, MM_One); m_apm_sqrt(tmp1, (places + 6), tmp2); m_apm_add(tmp2, tmp0, tmp1); m_apm_log(rr, places, tmp2); rr->m_apm_sign = aa->m_apm_sign; /* fix final sign */ M_restore_stack(3); }
/* * arctanh(x) == 0.5 * log [ (1 + x) / (1 - x) ] * * |x| < 1.0 */ void m_apm_arctanh(M_APM rr, int places, M_APM aa) { M_APM tmp1, tmp2, tmp3; int ii, local_precision; tmp1 = M_get_stack_var(); m_apm_absolute_value(tmp1, aa); ii = m_apm_compare(tmp1, MM_One); if (ii >= 0) /* |x| >= 1.0 */ { M_apm_log_error_msg(M_APM_RETURN, "\'m_apm_arctanh\', |Argument| >= 1"); M_set_to_zero(rr); M_restore_stack(1); return; } tmp2 = M_get_stack_var(); tmp3 = M_get_stack_var(); local_precision = places + 8; m_apm_add(tmp1, MM_One, aa); m_apm_subtract(tmp2, MM_One, aa); m_apm_divide(tmp3, local_precision, tmp1, tmp2); m_apm_log(tmp2, local_precision, tmp3); m_apm_multiply(tmp1, tmp2, MM_0_5); m_apm_round(rr, places, tmp1); M_restore_stack(3); }
/* Calls the LOG function. The formula used is : log10(x) = A * log(x) where A = log (e) [0.43429448190325...] 10 */ void m_apm_log10(M_APM rr, int places, M_APM aa) { int dplaces; M_APM tmp8, tmp9; tmp8 = M_get_stack_var(); tmp9 = M_get_stack_var(); dplaces = places + 4; M_check_log_places(dplaces + 45); m_apm_log(tmp9, dplaces, aa); m_apm_multiply(tmp8, tmp9, MM_lc_log10R); m_apm_round(rr, places, tmp8); M_restore_stack(2); /* restore the 2 locals we used here */ }
void m_apm_log_mt(M_APM rr, int places, M_APM aa) { m_apm_enter(); m_apm_log(rr,places,aa); m_apm_leave(); }
/* Calculate the POW function by calling EXP : Y A X = e where A = Y * log(X) */ void m_apm_pow(M_APM rr, int places, M_APM xx, M_APM yy) { int iflag, pflag; char sbuf[64]; M_APM tmp8, tmp9; /* if yy == 0, return 1 */ if (yy->m_apm_sign == 0) { m_apm_copy(rr, MM_One); return; } /* if xx == 0, return 0 */ if (xx->m_apm_sign == 0) { M_set_to_zero(rr); return; } if (M_size_flag == 0) /* init locals on first call */ { M_size_flag = M_get_sizeof_int(); M_last_log_digits = 0; M_last_xx_input = m_apm_init(); M_last_xx_log = m_apm_init(); } /* * if 'yy' is a small enough integer, call the more * efficient _integer_pow function. */ if (m_apm_is_integer(yy)) { iflag = FALSE; if (M_size_flag == 2) /* 16 bit compilers */ { if (yy->m_apm_exponent <= 4) iflag = TRUE; } else /* >= 32 bit compilers */ { if (yy->m_apm_exponent <= 7) iflag = TRUE; } if (iflag) { m_apm_to_integer_string(sbuf, yy); m_apm_integer_pow(rr, places, xx, atoi(sbuf)); return; } } tmp8 = M_get_stack_var(); tmp9 = M_get_stack_var(); /* * If parameter 'X' is the same this call as it * was the previous call, re-use the saved log * calculation from last time. */ pflag = FALSE; if (M_last_log_digits >= places) { if (m_apm_compare(xx, M_last_xx_input) == 0) pflag = TRUE; } if (pflag) { m_apm_round(tmp9, (places + 8), M_last_xx_log); } else { m_apm_log(tmp9, (places + 8), xx); M_last_log_digits = places + 2; /* save the 'X' input value and the log calculation */ m_apm_copy(M_last_xx_input, xx); m_apm_copy(M_last_xx_log, tmp9); } m_apm_multiply(tmp8, tmp9, yy); m_apm_exp(rr, places, tmp8); M_restore_stack(2); /* restore the 2 locals we used here */ }