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