summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asin.c3
-rw-r--r--asinh.c3
-rw-r--r--atan.c10
-rw-r--r--atanh.c5
-rw-r--r--sin.c5
-rw-r--r--sinh.c3
-rw-r--r--tan.c5
-rw-r--r--tanh.c9
8 files changed, 32 insertions, 11 deletions
diff --git a/asin.c b/asin.c
index ae36f4715..443b41c55 100644
--- a/asin.c
+++ b/asin.c
@@ -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);
diff --git a/asinh.c b/asinh.c
index 72f9fe647..7f48d4297 100644
--- a/asinh.c
+++ b/asinh.c
@@ -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);
diff --git a/atan.c b/atan.c
index 8847c6f58..84bc2e546 100644
--- a/atan.c
+++ b/atan.c
@@ -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)
{
diff --git a/atanh.c b/atanh.c
index af7660985..608d596b2 100644
--- a/atanh.c
+++ b/atanh.c
@@ -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;
diff --git a/sin.c b/sin.c
index b3c40322c..47e3b7842 100644
--- a/sin.c
+++ b/sin.c
@@ -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);
diff --git a/sinh.c b/sinh.c
index decee31f3..b871d049c 100644
--- a/sinh.c
+++ b/sinh.c
@@ -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);
{
diff --git a/tan.c b/tan.c
index 5b7411dbb..78e38b0ee 100644
--- a/tan.c
+++ b/tan.c
@@ -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 */
diff --git a/tanh.c b/tanh.c
index b7c59a239..b4c01101d 100644
--- a/tanh.c
+++ b/tanh.c
@@ -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 */