1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #if defined(LIBM_SCCS) && !defined(lint)
- static char rcsid[] = "$NetBSD: e_log10.c,v 1.9 1995/05/10 20:45:51 jtc Exp $";
- #endif
- #include "math.h"
- #include "math_private.h"
- #ifdef __STDC__
- static const double
- #else
- static double
- #endif
- two54 = 1.80143985094819840000e+16,
- ivln10 = 4.34294481903251816668e-01,
- log10_2hi = 3.01029995663611771306e-01,
- log10_2lo = 3.69423907715893078616e-13;
- #ifdef __STDC__
- static const double zero = 0.0;
- #else
- static double zero = 0.0;
- #endif
- #ifdef __STDC__
- double __ieee754_log10(double x)
- #else
- double __ieee754_log10(x)
- double x;
- #endif
- {
- double y,z;
- int32_t i,k,hx;
- u_int32_t lx;
- EXTRACT_WORDS(hx,lx,x);
- k=0;
- if (hx < 0x00100000) {
- if (((hx&0x7fffffff)|lx)==0)
- return -two54/zero;
- if (hx<0) return (x-x)/zero;
- k -= 54; x *= two54;
- GET_HIGH_WORD(hx,x);
- }
- if (hx >= 0x7ff00000) return x+x;
- k += (hx>>20)-1023;
- i = ((u_int32_t)k&0x80000000)>>31;
- hx = (hx&0x000fffff)|((0x3ff-i)<<20);
- y = (double)(k+i);
- SET_HIGH_WORD(x,hx);
- z = y*log10_2lo + ivln10*__ieee754_log(x);
- return z+y*log10_2hi;
- }
|