diff options
-rw-r--r-- | asin.c | 3 | ||||
-rw-r--r-- | asinh.c | 3 | ||||
-rw-r--r-- | atan.c | 10 | ||||
-rw-r--r-- | atanh.c | 5 | ||||
-rw-r--r-- | sin.c | 5 | ||||
-rw-r--r-- | sinh.c | 3 | ||||
-rw-r--r-- | tan.c | 5 | ||||
-rw-r--r-- | tanh.c | 9 |
8 files changed, 32 insertions, 11 deletions
@@ -50,6 +50,9 @@ mpfr_asin (mpfr_ptr asin, mpfr_srcptr x, mp_rnd_t rnd_mode) } } + /* asin(x) = x + x^3/6 + ... so the error is < 2^(3*EXP(x)-2) */ + MPFR_FAST_COMPUTE_IF_SMALL_INPUT (asin,x, -2*MPFR_GET_EXP (x)+2,1,rnd_mode,); + /* Set x_p=|x| (x is a normal number) */ mpfr_init2 (xp, MPFR_PREC (x)); inexact = mpfr_abs (xp, x, GMP_RNDN); @@ -61,6 +61,9 @@ mpfr_asinh (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) } } + /* asinh(x) = x - x^3/6 + ... so the error is < 2^(3*EXP(x)-2) */ + MPFR_FAST_COMPUTE_IF_SMALL_INPUT (y, x, -2*MPFR_GET_EXP (x)+2,0,rnd_mode,); + Ny = MPFR_PREC (y); /* Precision of output variable */ signx = MPFR_SIGN (x); @@ -202,6 +202,11 @@ mpfr_atan (mpfr_ptr atan, mpfr_srcptr x, mp_rnd_t rnd_mode) } } + /* atan(x) = x - x^3/3 + x^5/5... + so the error is < 2^(3*EXP(x)-1) + so `EXP(x)-(3*EXP(x)-1)` = -2*EXP(x)+1 */ + MPFR_FAST_COMPUTE_IF_SMALL_INPUT (atan,x, -2*MPFR_GET_EXP (x)+1,0,rnd_mode,); + /* Set x_p=|x| */ MPFR_TMP_INIT_ABS (xp, x); @@ -223,11 +228,6 @@ mpfr_atan (mpfr_ptr atan, mpfr_srcptr x, mp_rnd_t rnd_mode) return inexact; } - /* atan(x) = x - x^3/3 + x^5/5... - so the error is < 2^(3*EXP(x)-1) - so `EXP(x)-(3*EXP(x)-1)` = -2*EXP(x)+1 */ - MPFR_FAST_COMPUTE_IF_SMALL_INPUT (atan,x, -2*MPFR_GET_EXP (x)+1,0,rnd_mode,); - realprec = MPFR_PREC (atan) + MPFR_INT_CEIL_LOG2 (MPFR_PREC (atan)) + 4; /* if (MPFR_PREC (atan) + 5 > MPFR_PREC (x) && MPFR_GET_EXP (x) < 0) { @@ -70,12 +70,15 @@ mpfr_atanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode) MPFR_RET_NAN; } + /* atanh(x) = x + x^3/3 + ... so the error is < 2^(3*EXP(x)-1) */ + MPFR_FAST_COMPUTE_IF_SMALL_INPUT (y, x, -2*MPFR_GET_EXP (x)+1,1,rnd_mode,); + MPFR_SAVE_EXPO_MARK (expo); /* Compute initial precision */ Nx = MPFR_PREC (xt); MPFR_TMP_INIT_ABS (x, xt); - Ny = MPFR_PREC (y); + Ny = MPFR_PREC (y); Nt = MAX (Nx, Ny); /* the optimal number of bits : see algorithms.ps */ Nt = Nt + MPFR_INT_CEIL_LOG2 (Nt) + 4; @@ -128,11 +128,14 @@ mpfr_sin (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) } } + /* sin(x) = x - x^3/6 + ... so the error is < 2^(3*EXP(x)-2) */ + MPFR_FAST_COMPUTE_IF_SMALL_INPUT (y, x, -2*MPFR_GET_EXP (x)+2,0,rnd_mode, ); + /* Compute initial precision */ precy = MPFR_PREC (y); m = precy + MPFR_INT_CEIL_LOG2 (precy) + 13; e = MPFR_GET_EXP (x); - m += (e < 0) ? -2*e : e; + m += (e < 0) ? -2*e : e; sign = mpfr_sin_sign (x); mpfr_init2 (c, m); @@ -56,6 +56,9 @@ mpfr_sinh (mpfr_ptr y, mpfr_srcptr xt, mp_rnd_t rnd_mode) } } + /* sinh(x) = x + x^3/6 + ... so the error is < 2^(3*EXP(x)-2) */ + MPFR_FAST_COMPUTE_IF_SMALL_INPUT (y, xt, -2*MPFR_GET_EXP(xt)+2,1,rnd_mode, ); + MPFR_TMP_INIT_ABS (x, xt); { @@ -23,7 +23,7 @@ MA 02111-1307, USA. */ #include "mpfr-impl.h" /* computes tan(x) = sign(x)*sqrt(1/cos(x)^2-1) */ -int +int mpfr_tan (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) { mp_prec_t precy, m; @@ -51,6 +51,9 @@ mpfr_tan (mpfr_ptr y, mpfr_srcptr x, mp_rnd_t rnd_mode) } } + /* tan(x) = x + x^3/3 + ... so the error is < 2^(3*EXP(x)-1) */ + MPFR_FAST_COMPUTE_IF_SMALL_INPUT (y, x, -2*MPFR_GET_EXP (x)+1,1,rnd_mode, ); + MPFR_SAVE_EXPO_MARK (expo); /* Compute initial precision */ @@ -38,7 +38,7 @@ mpfr_tanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode) { if (MPFR_IS_NAN (xt)) { - MPFR_SET_NAN (y); + MPFR_SET_NAN (y); MPFR_RET_NAN; } else if (MPFR_IS_INF (xt)) @@ -54,10 +54,13 @@ mpfr_tanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode) MPFR_RET (0); } } - + + /* tanh(x) = x - x^3/3 + ... so the error is < 2^(3*EXP(x)-1) */ + MPFR_FAST_COMPUTE_IF_SMALL_INPUT (y, xt, -2*MPFR_GET_EXP(xt)+1,0,rnd_mode, ); + MPFR_SAVE_EXPO_MARK (expo); MPFR_TMP_INIT_ABS (x, xt); - + /* General case */ { /* Declaration of the intermediary variable */ |