00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #if defined(LIBM_SCCS) && !defined(lint)
00014 static char rcsid[] = "$NetBSD: s_tanh.c,v 1.7 1995/05/10 20:48:22 jtc Exp $";
00015 #endif
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "math.h"
00042 #include "mathP.h"
00043
00044 #ifdef __STDC__
00045 static const double one=1.0, two=2.0, tiny = 1.0e-300;
00046 #else
00047 static double one=1.0, two=2.0, tiny = 1.0e-300;
00048 #endif
00049
00050 #ifdef __STDC__
00051 double tanh(double x)
00052 #else
00053 double tanh(x)
00054 double x;
00055 #endif
00056 {
00057 double t,z;
00058 int32_t jx,ix;
00059
00060
00061 GET_HIGH_WORD(jx,x);
00062 ix = jx&0x7fffffff;
00063
00064
00065 if(ix>=0x7ff00000) {
00066 if (jx>=0) return one/x+one;
00067 else return one/x-one;
00068 }
00069
00070
00071 if (ix < 0x40360000) {
00072 if (ix<0x3c800000)
00073 return x*(one+x);
00074 if (ix>=0x3ff00000) {
00075 t = expm1(two*fabs(x));
00076 z = one - two/(t+two);
00077 } else {
00078 t = expm1(-two*fabs(x));
00079 z= -t/(t+two);
00080 }
00081
00082 } else {
00083 z = one - tiny;
00084 }
00085 return (jx>=0)? z: -z;
00086 }