1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- #if defined(LIBM_SCCS) && !defined(lint)
- static char rcsid[] = "$NetBSD: s_tanh.c,v 1.7 1995/05/10 20:48:22 jtc Exp $";
- #endif
- #include "math.h"
- #include "math_private.h"
- #ifdef __STDC__
- static const double one=1.0, two=2.0, tiny = 1.0e-300;
- #else
- static double one=1.0, two=2.0, tiny = 1.0e-300;
- #endif
- #ifdef __STDC__
- double tanh(double x)
- #else
- double tanh(x)
- double x;
- #endif
- {
- double t,z;
- int32_t jx,ix;
-
- GET_HIGH_WORD(jx,x);
- ix = jx&0x7fffffff;
-
- if(ix>=0x7ff00000) {
- if (jx>=0) return one/x+one;
- else return one/x-one;
- }
-
- if (ix < 0x40360000) {
- if (ix<0x3c800000)
- return x*(one+x);
- if (ix>=0x3ff00000) {
- t = expm1(two*fabs(x));
- z = one - two/(t+two);
- } else {
- t = expm1(-two*fabs(x));
- z= -t/(t+two);
- }
-
- } else {
- z = one - tiny;
- }
- return (jx>=0)? z: -z;
- }
|