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.log1p.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
00076 #if defined(mips) && !defined(__GNUC__)
00077 extern double log1p(double);
00078
00079 #pragma weak log1p = __log1p
00080 #endif
00081
00082 #if defined(BUILD_OS_DARWIN)
00083 extern double __log1p(double);
00084 #pragma weak log1p
00085 double log1p( double x ) {
00086 return __log1p( x );
00087 }
00088 #elif defined(__GNUC__)
00089 extern double __log1p(double);
00090
00091 double log1p() __attribute__ ((weak, alias ("__log1p")));
00092
00093 #endif
00094
00095 extern const du _logtabhi[];
00096 extern const du _logtablo[];
00097 extern const du _log_ru[];
00098
00099 static const du Qnan =
00100 {D(QNANHI, QNANLO)};
00101
00102 static const du Neginf =
00103 {D(0xfff00000, 0x00000000)};
00104
00105 static const du Inf =
00106 {D(0x7ff00000, 0x00000000)};
00107
00108 static const du m_one =
00109 {D(0xbff00000, 0x00000000)};
00110
00111 static const du twop7 =
00112 {D(0x40600000, 0x00000000)};
00113
00114 static const du twopm7 =
00115 {D(0x3f800000, 0x00000000)};
00116
00117
00118
00119 static const du T1 =
00120 {D(0xbfaf0540, 0x438fd5c4)};
00121
00122
00123
00124 static const du T2 =
00125 {D(0x3fb082b5, 0x77d34ed8)};
00126
00127 static const du T3 =
00128 {D(0x43500000, 0x00000000)};
00129
00130 static const du log2_lead =
00131 {D(0x3fe62e42, 0xfefa4000)};
00132
00133 static const du log2_trail =
00134 {D(0xbd48432a, 0x1b0e2634)};
00135
00136
00137
00138 static const du P[] =
00139 {
00140 {D(0x3ff00000, 0x00000000)},
00141 {D(0xbfe00000, 0x00000001)},
00142 {D(0x3fd55555, 0x55509ba5)},
00143 {D(0xbfcfffff, 0xffeb6526)},
00144 {D(0x3fc999b4, 0xdfed6fe4)},
00145 {D(0xbfc55576, 0x66472e04)},
00146 };
00147
00148
00149
00150
00151
00152 static const du Q[] =
00153 {
00154 {D(0x3ff00000, 0x00000000)},
00155 {D(0x3fb55555, 0x555554ed)},
00156 {D(0x3f899999, 0x99b929bd)},
00157 {D(0x3f624923, 0x14d70150)},
00158 {D(0x3f3c7ff7, 0xdaa9e72e)},
00159 };
00160
00161 #ifdef _32BIT_MACHINE
00162
00163 static const int one =
00164 {0x3ff00000};
00165
00166 #else
00167
00168 static const long long one =
00169 {0x3ff0000000000000ll};
00170
00171 #endif
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 double
00184 __log1p( double x )
00185 {
00186 #ifdef _32BIT_MACHINE
00187
00188 int xpt;
00189 int k, m, n;
00190
00191 #else
00192
00193 long long xpt;
00194 long long k, m, n;
00195
00196 #endif
00197 int j;
00198 double g, u, v, x1, x2;
00199 double u1, u2;
00200 double q;
00201 double twopnegm;
00202 double result;
00203 double y, f, F;
00204 double l_lead, l_trail;
00205 #ifdef _CALL_MATHERR
00206 struct exception exstruct;
00207 #endif
00208
00209 if ( x != x )
00210 {
00211
00212
00213 #ifdef _CALL_MATHERR
00214
00215 exstruct.type = DOMAIN;
00216 exstruct.name = "log1p";
00217 exstruct.arg1 = x;
00218 exstruct.retval = Qnan.d;
00219
00220 if ( matherr( &exstruct ) == 0 )
00221 {
00222 fprintf(stderr, "domain error in log1p\n");
00223 SETERRNO(EDOM);
00224 }
00225
00226 return ( exstruct.retval );
00227 #else
00228 NAN_SETERRNO(EDOM);
00229
00230 return ( Qnan.d );
00231 #endif
00232 }
00233
00234 if ( (T1.d < x) && (x < T2.d) )
00235 {
00236 #ifdef _32BIT_MACHINE
00237
00238 DBLHI2INT(x, xpt);
00239 #else
00240 DBL2LL(x, xpt);
00241 #endif
00242 xpt >>= DMANTWIDTH;
00243 xpt &= 0x7ff;
00244
00245 if ( xpt >= 0x3ca )
00246 {
00247
00248
00249 g = 1.0/(2.0 + x);
00250
00251 u = x*g;
00252 u = u + u;
00253 v = u*u;
00254
00255 q = (((Q[4].d*v + Q[3].d)*v + Q[2].d)*v +
00256 Q[1].d)*v*u;
00257
00258 u1 = (float)u;
00259 x1 = (float)x;
00260
00261 x2 = x - x1;
00262 u2 = x - u1;
00263 u2 = u2 + u2;
00264 u2 = ((u2 - u1*x1) - u1*x2)*g;
00265
00266 result = u1 + (u2 + q);
00267
00268 return ( result );
00269 }
00270
00271 return ( x );
00272 }
00273 else if ( (x > m_one.d) && (x != Inf.d) )
00274 {
00275 if ( x >= T3.d )
00276 y = x;
00277 else
00278 y = 1.0 + x;
00279
00280 #ifdef _32BIT_MACHINE
00281
00282 DBLHI2INT(y, k);
00283 #else
00284 DBL2LL(y, k);
00285 #endif
00286 m = (k >> DMANTWIDTH);
00287 m -= DEXPBIAS;
00288
00289 k &= DEXPMASK;
00290 k |= one;
00291
00292 #ifdef _32BIT_MACHINE
00293
00294 INT2DBLHI(k, y);
00295 #else
00296 LL2DBL(k, y);
00297 #endif
00298 u = twop7.d*y;
00299
00300 j = ROUND(u);
00301
00302 F = j;
00303 j -= 128;
00304
00305 F = twopm7.d*F;
00306
00307 if ( m <= -2 )
00308 f = y - F;
00309 else
00310 {
00311 n = DEXPBIAS - m;
00312 n <<= DMANTWIDTH;
00313
00314 #ifdef _32BIT_MACHINE
00315
00316 twopnegm = 0.0;
00317 INT2DBLHI(n, twopnegm);
00318 #else
00319 LL2DBL(n, twopnegm);
00320 #endif
00321 if ( m <= 52 )
00322 f = (twopnegm - F) + twopnegm*x;
00323 else if ( m <= 108 )
00324 f = (twopnegm*x - F) + twopnegm;
00325 else
00326 f = y - F;
00327 }
00328
00329
00330
00331
00332
00333
00334 if ( j > 64 )
00335 m++;
00336
00337 u = _log_ru[j].d*f;
00338
00339 q = ((((P[5].d*u + P[4].d)*u + P[3].d)*u +
00340 P[2].d)*u + P[1].d)*(u*u);
00341
00342
00343 l_lead = _logtabhi[j].d;
00344 l_trail = _logtablo[j].d;
00345
00346 l_lead += m*log2_lead.d;
00347 l_trail += m*log2_trail.d;
00348
00349 result = l_lead + (u + (q + l_trail));
00350
00351 return ( result );
00352 }
00353
00354 if ( x == Inf.d )
00355 {
00356 #ifdef _CALL_MATHERR
00357
00358 exstruct.type = DOMAIN;
00359 exstruct.name = "log1p";
00360 exstruct.arg1 = x;
00361 exstruct.retval = Inf.d;
00362
00363 if ( matherr( &exstruct ) == 0 )
00364 {
00365 fprintf(stderr, "domain error in log1p\n");
00366 SETERRNO(EDOM);
00367 }
00368
00369 return ( exstruct.retval );
00370 #else
00371 SETERRNO(EDOM);
00372
00373 return ( Inf.d );
00374 #endif
00375 }
00376
00377 if ( x == m_one.d )
00378 {
00379 #ifdef _CALL_MATHERR
00380
00381 exstruct.type = OVERFLOW;
00382 exstruct.name = "log1p";
00383 exstruct.arg1 = x;
00384 exstruct.retval = Neginf.d;
00385
00386 if ( matherr( &exstruct ) == 0 )
00387 {
00388 fprintf(stderr, "overflow range error in log1p\n");
00389 SETERRNO(ERANGE);
00390 }
00391
00392 return ( exstruct.retval );
00393 #else
00394 SETERRNO(ERANGE);
00395
00396 return ( Neginf.d );
00397 #endif
00398 }
00399
00400 if ( x == Neginf.d )
00401 {
00402 #ifdef _CALL_MATHERR
00403
00404 exstruct.type = DOMAIN;
00405 exstruct.name = "log1p";
00406 exstruct.arg1 = x;
00407 exstruct.retval = Qnan.d;
00408
00409 if ( matherr( &exstruct ) == 0 )
00410 {
00411 fprintf(stderr, "domain error in log1p\n");
00412 SETERRNO(EDOM);
00413 }
00414
00415 return ( exstruct.retval );
00416 #else
00417 SETERRNO(EDOM);
00418
00419 return ( Qnan.d );
00420 #endif
00421 }
00422
00423
00424
00425 #ifdef _CALL_MATHERR
00426
00427 exstruct.type = DOMAIN;
00428 exstruct.name = "log1p";
00429 exstruct.arg1 = x;
00430 exstruct.retval = Qnan.d;
00431
00432 if ( matherr( &exstruct ) == 0 )
00433 {
00434 fprintf(stderr, "domain error in log1p\n");
00435 SETERRNO(EDOM);
00436 }
00437
00438 return ( exstruct.retval );
00439 #else
00440 SETERRNO(EDOM);
00441
00442 return ( Qnan.d );
00443 #endif
00444 }
00445
00446 #ifdef NO_LONG_DOUBLE
00447
00448 #if defined(BUILD_OS_DARWIN)
00449 extern long double __log1pl(long double);
00450 long double log1pl( long double x ) {
00451 return ( (long double)__log1p((double)x) );
00452 }
00453 #elif defined(__GNUC__)
00454 extern long double __log1pl(long double);
00455
00456 long double log1pl() __attribute__ ((weak, alias ("__log1pl")));
00457
00458 #endif
00459
00460 long double
00461 __log1pl( long double x )
00462 {
00463 return ( (long double)__log1p((double)x) );
00464 }
00465
00466 #endif
00467