diff options
-rw-r--r-- | lib/msun/src/s_tanh.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/msun/src/s_tanh.c b/lib/msun/src/s_tanh.c index e3bbf47..a05ad30 100644 --- a/lib/msun/src/s_tanh.c +++ b/lib/msun/src/s_tanh.c @@ -24,14 +24,14 @@ static char rcsid[] = "$FreeBSD$"; * x -x * e + e * 1. reduce x to non-negative by tanh(-x) = -tanh(x). - * 2. 0 <= x <= 2**-55 : tanh(x) := x*(one+x) + * 2. 0 <= x < 2**-28 : tanh(x) := x with inexact if x != 0 * -t - * 2**-55 < x <= 1 : tanh(x) := -----; t = expm1(-2x) + * 2**-28 <= x < 1 : tanh(x) := -----; t = expm1(-2x) * t + 2 * 2 - * 1 <= x <= 22.0 : tanh(x) := 1- ----- ; t=expm1(2x) + * 1 <= x < 22 : tanh(x) := 1 - -----; t = expm1(2x) * t + 2 - * 22.0 < x <= INF : tanh(x) := 1. + * 22 <= x <= INF : tanh(x) := 1. * * Special cases: * tanh(NaN) is NaN; @@ -41,7 +41,7 @@ static char rcsid[] = "$FreeBSD$"; #include "math.h" #include "math_private.h" -static const double one=1.0, two=2.0, tiny = 1.0e-300; +static const double one = 1.0, two = 2.0, tiny = 1.0e-300, huge = 1.0e300; double tanh(double x) @@ -49,7 +49,6 @@ tanh(double x) double t,z; int32_t jx,ix; - /* High word of |x|. */ GET_HIGH_WORD(jx,x); ix = jx&0x7fffffff; @@ -61,8 +60,9 @@ tanh(double x) /* |x| < 22 */ if (ix < 0x40360000) { /* |x|<22 */ - if (ix<0x3c800000) /* |x|<2**-55 */ - return x*(one+x); /* tanh(small) = small */ + if (ix<0x3e300000) { /* |x|<2**-28 */ + if(huge+x>one) return x; /* tanh(tiny) = tiny with inexact */ + } if (ix>=0x3ff00000) { /* |x|>=1 */ t = expm1(two*fabs(x)); z = one - two/(t+two); @@ -70,9 +70,9 @@ tanh(double x) t = expm1(-two*fabs(x)); z= -t/(t+two); } - /* |x| > 22, return +-1 */ + /* |x| >= 22, return +-1 */ } else { - z = one - tiny; /* raised inexact flag */ + z = one - tiny; /* raise inexact flag */ } return (jx>=0)? z: -z; } |