00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 static char *rcs_id = "$Source: /home/bos/bk/kpro64-pending/libm/mips/SCCS/s.tanhf.c $ $Revision: 1.5 $";
00060
00061 #ifdef _CALL_MATHERR
00062 #include <stdio.h>
00063 #include <math.h>
00064 #include <errno.h>
00065 #endif
00066
00067 #include "libm.h"
00068
00069 #if defined(mips) && !defined(__GNUC__)
00070 extern float ftanh(float);
00071 extern float tanhf(float);
00072
00073 #pragma weak ftanh = __tanhf
00074 #pragma weak tanhf = __tanhf
00075 #endif
00076
00077 #if defined(BUILD_OS_DARWIN)
00078 extern float __tanhf(float);
00079 #pragma weak tanhf
00080 float tanhf( float x ) {
00081 return __tanhf( x );
00082 }
00083 #elif defined(__GNUC__)
00084 extern float __tanhf(float);
00085 float tanhf(float) __attribute__ ((weak, alias ("__tanhf")));
00086 #endif
00087
00088
00089
00090
00091
00092 static const du P[] =
00093 {
00094 {D(0x3ff00000, 0x00000000)},
00095 {D(0x3ff00000, 0x00000000)},
00096 {D(0x3fe00008, 0x745da559)},
00097 {D(0x3fc55569, 0x9fd0029e)},
00098 };
00099
00100
00101
00102
00103
00104 static const du P2[] =
00105 {
00106 {D(0x3ff00000, 0x00000000)},
00107 {D(0xbfd55555, 0x10101b35)},
00108 {D(0x3fc110f2, 0x1b30079f)},
00109 {D(0xbfab98ac, 0xb894835d)},
00110 {D(0x3f95cf23, 0xf79c6537)},
00111 {D(0xbf7b3a65, 0x369caf92)},
00112 };
00113
00114 static const du rln2by32 =
00115 {D(0x40471547, 0x652b82fe)};
00116
00117 static const du ln2by32hi =
00118 {D(0x3f962e42, 0xfef00000)};
00119
00120 static const du ln2by32lo =
00121 {D(0x3d8473de, 0x6af278ed)};
00122
00123 extern const du _expftab[];
00124
00125 static const fu Qnan = {QNANF};
00126
00127 static const fu Ulimit = {0x41102cb3};
00128
00129 static const fu Llimit = {0xc1102cb3};
00130
00131 static const fu f_one = {0x3f800000};
00132
00133 static const fu f_m_one = {0xbf800000};
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 float
00146 __tanhf( float x )
00147 {
00148 #ifdef _32BIT_MACHINE
00149
00150 int l;
00151
00152 #else
00153
00154 long long l;
00155
00156 #endif
00157
00158 int ix, xpt;
00159 int r, m, k;
00160 double dx, absdx;
00161 double twopk;
00162 double result;
00163 double md;
00164 double xsq;
00165 double y, t;
00166 double poly;
00167 #ifdef _CALL_MATHERR
00168 struct exception exstruct;
00169 #endif
00170
00171
00172
00173 FLT2INT(x, ix);
00174 xpt = (ix >> MANTWIDTH);
00175 xpt &= 0xff;
00176
00177 if ( xpt < 0x82 )
00178 {
00179
00180
00181 if ( xpt >= 0x7e )
00182 {
00183
00184 L:
00185 dx = x;
00186 absdx = fabs(dx);
00187
00188
00189
00190 absdx += absdx;
00191
00192
00193
00194 md = absdx*rln2by32.d;
00195 m = ROUND(md);
00196 md = m;
00197
00198 r = m & 0x1f;
00199
00200
00201
00202 k = m >> 5;
00203
00204 y = (absdx - md*ln2by32hi.d) - md*ln2by32lo.d;
00205
00206
00207
00208 t = _expftab[r].d;
00209
00210
00211
00212 poly = ((P[3].d*y + P[2].d)*y + P[1].d)*y;
00213
00214
00215
00216 result = t + t*poly;
00217
00218 l = k + DEXPBIAS;
00219 l <<= DMANTWIDTH;
00220
00221
00222
00223 #ifdef _32BIT_MACHINE
00224
00225 twopk = 0.0;
00226 INT2DBLHI(l, twopk);
00227 #else
00228 LL2DBL(l, twopk);
00229 #endif
00230 result *= twopk;
00231
00232 result = 1.0 - 2.0/(result + 1.0);
00233
00234 if ( x < (float)0.0 )
00235 result = -result;
00236
00237 return ( result );
00238 }
00239
00240 if ( xpt >= 0x73 )
00241 {
00242
00243
00244
00245
00246 dx = x;
00247
00248 xsq = dx*dx;
00249
00250 result = ((((P2[5].d*xsq + P2[4].d)*xsq + P2[3].d)*xsq +
00251 P2[2].d)*xsq + P2[1].d)*(xsq*dx) + dx;
00252
00253 return ( (float)result );
00254 }
00255
00256 return ( x );
00257 }
00258
00259 if ( x != x )
00260 {
00261
00262
00263 #ifdef _CALL_MATHERR
00264
00265 exstruct.type = DOMAIN;
00266 exstruct.name = "tanhf";
00267 exstruct.arg1 = x;
00268 exstruct.retval = Qnan.f;
00269
00270 if ( matherr( &exstruct ) == 0 )
00271 {
00272 fprintf(stderr, "domain error in tanhf\n");
00273 SETERRNO(EDOM);
00274 }
00275
00276 return ( exstruct.retval );
00277 #else
00278 NAN_SETERRNO(EDOM);
00279
00280 return ( Qnan.f );
00281 #endif
00282 }
00283
00284 if ( x > Ulimit.f )
00285 return ( f_one.f );
00286
00287 if ( x < Llimit.f )
00288 return ( f_m_one.f );
00289
00290 goto L;
00291
00292 }
00293