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.expm1.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
00070
00071
00072
00073
00074
00075 #if defined(mips) && !defined(__GNUC__)
00076 extern double expm1(double);
00077
00078 #pragma weak expm1 = __expm1
00079 #endif
00080
00081 #if defined(BUILD_OS_DARWIN)
00082 extern double __expm1(double);
00083 #pragma weak expm1
00084 double expm1( double x ) {
00085 return __expm1( x );
00086 }
00087 #elif defined(__GNUC__)
00088 extern double __expm1(double);
00089
00090 double expm1() __attribute__ ((weak, alias ("__expm1")));
00091
00092 #endif
00093
00094 extern const du _exptabhi[];
00095 extern const du _exptablo[];
00096
00097 static const du Qnan =
00098 {D(QNANHI, QNANLO)};
00099
00100 static const du Inf =
00101 {D(0x7ff00000, 0x00000000)};
00102
00103
00104
00105 static const du T1 =
00106 {D(0xbfd26962, 0x1134db93)};
00107
00108
00109
00110 static const du T2 =
00111 {D(0x3fcc8ff7, 0xc79a9a22)};
00112
00113 static const du Twopm100 =
00114 {D(0x39b00000, 0x00000000)};
00115
00116 static const du Twopm7 =
00117 {D(0x3f800000, 0x00000000)};
00118
00119 static const du Ulimit =
00120 {D(0x40862e42, 0xfefa39ef)};
00121
00122 static const du Llimit =
00123 {D(0xc042b708, 0x872320e1)};
00124
00125 static const du rln2by32 =
00126 {D(0x40471547, 0x652b82fe)};
00127
00128 static const du ln2by32hi =
00129 {D(0x3f962e42, 0xfef00000)};
00130
00131 static const du ln2by32lo =
00132 {D(0x3d8473de, 0x6af278ed)};
00133
00134 static const du m_one =
00135 {D(0xbff00000, 0x00000000)};
00136
00137
00138
00139
00140
00141 static const du P[] =
00142 {
00143 {D(0x3fc55555, 0x55555549)},
00144 {D(0x3fa55555, 0x555554b6)},
00145 {D(0x3f811111, 0x1111a9f3)},
00146 {D(0x3f56c16c, 0x16ce14c6)},
00147 {D(0x3f2a01a0, 0x1159dd2d)},
00148 {D(0x3efa019f, 0x635825c4)},
00149 {D(0x3ec71e14, 0xbfe3db59)},
00150 {D(0x3e928295, 0x484734ea)},
00151 {D(0x3e5a2836, 0xaa646b96)},
00152 };
00153
00154
00155
00156 static const du Q[] =
00157 {
00158 {D(0x3ff00000, 0x00000000)},
00159 {D(0x3ff00000, 0x00000000)},
00160 {D(0x3fe00000, 0x00000000)},
00161 {D(0x3fc55555, 0x55548f7c)},
00162 {D(0x3fa55555, 0x55545d4e)},
00163 {D(0x3f811115, 0xb7aa905e)},
00164 {D(0x3f56c172, 0x8d739765)},
00165 };
00166
00167
00168
00169 static const fu twopowm[] =
00170 {
00171 {0x43000000},
00172 {0x42800000},
00173 {0x42000000},
00174 {0x41800000},
00175 {0x41000000},
00176 {0x40800000},
00177 {0x40000000},
00178 {0x3f800000},
00179 {0x3f000000},
00180 {0x3e800000},
00181 {0x3e000000},
00182 {0x3d800000},
00183 {0x3d000000},
00184 {0x3c800000},
00185 {0x3c000000},
00186 {0x3b800000},
00187 {0x3b000000},
00188 {0x3a800000},
00189 {0x3a000000},
00190 {0x39800000},
00191 {0x39000000},
00192 {0x38800000},
00193 {0x38000000},
00194 {0x37800000},
00195 {0x37000000},
00196 {0x36800000},
00197 {0x36000000},
00198 {0x35800000},
00199 {0x35000000},
00200 {0x34800000},
00201 {0x34000000},
00202 {0x33800000},
00203 {0x33000000},
00204 {0x32800000},
00205 {0x32000000},
00206 {0x31800000},
00207 {0x31000000},
00208 {0x30800000},
00209 {0x30000000},
00210 {0x2f800000},
00211 {0x2f000000},
00212 {0x2e800000},
00213 {0x2e000000},
00214 {0x2d800000},
00215 {0x2d000000},
00216 {0x2c800000},
00217 {0x2c000000},
00218 {0x2b800000},
00219 {0x2b000000},
00220 {0x2a800000},
00221 {0x2a000000},
00222 {0x29800000},
00223 {0x29000000},
00224 {0x28800000},
00225 {0x28000000},
00226 {0x27800000},
00227 {0x27000000},
00228 {0x26800000},
00229 {0x26000000},
00230 {0x25800000},
00231 };
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 double
00244 __expm1( double x )
00245 {
00246 #ifdef _32BIT_MACHINE
00247
00248 int ix, xpt;
00249 int k, l;
00250
00251 #else
00252
00253 long long ix, xpt;
00254 long long k, l;
00255
00256 #endif
00257
00258 int n, m, j;
00259 double y1, y2, y;
00260 double u, v, z;
00261 double p, q;
00262 double twopm;
00263 double twopmm;
00264 double nd;
00265 double s, s_lead, s_trail;
00266 double result;
00267 #ifdef _CALL_MATHERR
00268 struct exception exstruct;
00269 #endif
00270
00271
00272
00273 #ifdef _32BIT_MACHINE
00274
00275 DBLHI2INT(x, ix);
00276 #else
00277 DBL2LL(x, ix);
00278 #endif
00279 xpt = (ix >> DMANTWIDTH);
00280 xpt &= 0x7ff;
00281
00282 if ( xpt < 0x7ff )
00283 {
00284
00285
00286 if ( (T1.d < x) && (x < T2.d) )
00287 {
00288
00289
00290 if ( xpt >= 0x3c9 )
00291 {
00292
00293
00294 u = (float)x;
00295 v = x - u;
00296 y = u*u*0.5;
00297 z = v*(x + u)*0.5;
00298
00299 q = ((((((((P[8].d*x + P[7].d)*x + P[6].d)*x + P[5].d)*x +
00300 P[4].d)*x + P[3].d)*x + P[2].d)*x + P[1].d)*x +
00301 P[0].d)*(x*x*x);
00302
00303 if ( y >= Twopm7.d )
00304 {
00305 result = (u + y) + (q + (v + z));
00306 return ( result );
00307 }
00308
00309 result = x + (y + (q + z));
00310
00311 return ( result );
00312
00313 }
00314
00315 return ( x );
00316 }
00317 else if ( x > Ulimit.d )
00318 {
00319 #ifdef _CALL_MATHERR
00320 exstruct.type = OVERFLOW;
00321 exstruct.name = "expm1";
00322 exstruct.arg1 = x;
00323 exstruct.retval = Inf.d;
00324
00325 if ( matherr( &exstruct ) == 0 )
00326 {
00327 fprintf(stderr, "overflow range error in expm1\n");
00328 SETERRNO(ERANGE);
00329 }
00330
00331 return ( exstruct.retval );
00332 #else
00333 SETERRNO(ERANGE);
00334
00335 return ( Inf.d );
00336 #endif
00337 }
00338 else if ( x < Llimit.d )
00339 {
00340 return ( m_one.d + Twopm100.d );
00341 }
00342 else
00343 {
00344 nd = x*rln2by32.d;
00345 n = ROUND(nd);
00346 nd = n;
00347
00348 y1 = x - nd*ln2by32hi.d;
00349 y2 = nd*ln2by32lo.d;
00350 y = y1 - y2;
00351
00352 j = n & 0x1f;
00353 m = n >> 5;
00354
00355 s_lead = _exptabhi[j].d;
00356 s_trail = _exptablo[j].d;
00357
00358 q = ((((Q[6].d*y + Q[5].d)*y + Q[4].d)*y + Q[3].d)*y +
00359 Q[2].d)*(y*y);
00360
00361 p = (q - y2) + y1;
00362
00363 k = DEXPBIAS + m;
00364 k <<= DMANTWIDTH;
00365
00366 #ifdef _32BIT_MACHINE
00367
00368 twopm = 0.0;
00369 INT2DBLHI(k, twopm);
00370 #else
00371 LL2DBL(k, twopm);
00372 #endif
00373 if ( m >= 53 )
00374 {
00375 l = DEXPBIAS - m;
00376 l <<= DMANTWIDTH;
00377
00378 #ifdef _32BIT_MACHINE
00379
00380 twopmm = 0.0;
00381 INT2DBLHI(l, twopmm);
00382 #else
00383 LL2DBL(l, twopmm);
00384 #endif
00385 s = s_lead + s_trail;
00386 result = s_lead + (s*p + (s_trail - twopmm));
00387 result *= twopm;
00388 return ( result );
00389 }
00390 else if ( m >= -7 )
00391 {
00392 result = (s_lead - twopowm[m+7].f) +
00393 (s_lead*p + s_trail*(1.0 + p));
00394 result *= twopm;
00395 return ( result );
00396 }
00397 else
00398 {
00399 s = s_lead + s_trail;
00400 result = s_lead + (s*p + s_trail);
00401 result *= twopm;
00402 result -= 1.0;
00403 return ( result );
00404 }
00405 }
00406 }
00407 else if ( x != x )
00408 {
00409
00410
00411 #ifdef _CALL_MATHERR
00412
00413 exstruct.type = DOMAIN;
00414 exstruct.name = "expm1";
00415 exstruct.arg1 = x;
00416 exstruct.retval = Qnan.d;
00417
00418 if ( matherr( &exstruct ) == 0 )
00419 {
00420 fprintf(stderr, "domain error in expm1\n");
00421 SETERRNO(EDOM);
00422 }
00423
00424 return ( exstruct.retval );
00425 #else
00426 NAN_SETERRNO(EDOM);
00427
00428 return ( Qnan.d );
00429 #endif
00430 }
00431 else if ( x == Inf.d )
00432 {
00433 #ifdef _CALL_MATHERR
00434
00435 exstruct.type = OVERFLOW;
00436 exstruct.name = "expm1";
00437 exstruct.arg1 = x;
00438 exstruct.retval = Inf.d;
00439
00440 if ( matherr( &exstruct ) == 0 )
00441 {
00442 fprintf(stderr, "overflow range error in expm1\n");
00443 SETERRNO(ERANGE);
00444 }
00445
00446 return ( exstruct.retval );
00447 #else
00448 SETERRNO(ERANGE);
00449
00450 return ( Inf.d );
00451 #endif
00452 }
00453 else
00454
00455 return ( m_one.d );
00456 }
00457
00458 #ifdef NO_LONG_DOUBLE
00459
00460 #if defined(BUILD_OS_DARWIN)
00461 extern long double __expm1l(long double);
00462 long double expm1l( long double x ) {
00463 return ( (long double)__expm1((double)x) );
00464 }
00465 #elif defined(__GNUC__)
00466 extern long double __expm1l(long double);
00467
00468 long double expm1l() __attribute__ ((weak, alias ("__expm1l")));
00469
00470 #endif
00471
00472 long double
00473 __expm1l( long double x )
00474 {
00475 return ( (long double)__expm1((double)x) );
00476 }
00477
00478 #endif
00479