2005-02-04 18:26:06 +00:00
|
|
|
|
|
|
|
/* @(#)e_log10.c 1.3 95/01/18 */
|
1994-08-19 09:40:01 +00:00
|
|
|
/*
|
|
|
|
* ====================================================
|
|
|
|
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
|
|
*
|
2005-02-04 18:26:06 +00:00
|
|
|
* Developed at SunSoft, a Sun Microsystems, Inc. business.
|
1994-08-19 09:40:01 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this
|
2005-02-04 18:26:06 +00:00
|
|
|
* software is freely granted, provided that this notice
|
1994-08-19 09:40:01 +00:00
|
|
|
* is preserved.
|
|
|
|
* ====================================================
|
|
|
|
*/
|
|
|
|
|
2008-02-22 02:30:36 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-08-19 09:40:01 +00:00
|
|
|
|
2011-03-07 03:11:27 +00:00
|
|
|
/*
|
2011-10-15 05:00:56 +00:00
|
|
|
* Return the base 10 logarithm of x. See e_log.c and k_log.h for most
|
|
|
|
* comments.
|
1994-08-19 09:40:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "math.h"
|
|
|
|
#include "math_private.h"
|
2011-03-07 03:11:27 +00:00
|
|
|
#include "k_log.h"
|
1994-08-19 09:40:01 +00:00
|
|
|
|
|
|
|
static const double
|
|
|
|
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
|
2011-03-07 03:11:27 +00:00
|
|
|
ivln10hi = 4.34294481878168880939e-01, /* 0x3fdbcb7b, 0x15200000 */
|
|
|
|
ivln10lo = 2.50829467116452752298e-11, /* 0x3dbb9438, 0xca9aadd5 */
|
1994-08-19 09:40:01 +00:00
|
|
|
log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
|
|
|
|
log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
|
|
|
|
|
|
|
|
static const double zero = 0.0;
|
|
|
|
|
2002-05-28 18:15:04 +00:00
|
|
|
double
|
2003-07-23 04:53:47 +00:00
|
|
|
__ieee754_log10(double x)
|
1994-08-19 09:40:01 +00:00
|
|
|
{
|
2011-03-07 03:11:27 +00:00
|
|
|
double f,hi,lo,y,z;
|
1994-08-19 09:40:01 +00:00
|
|
|
int32_t i,k,hx;
|
|
|
|
u_int32_t lx;
|
|
|
|
|
|
|
|
EXTRACT_WORDS(hx,lx,x);
|
|
|
|
|
2011-10-15 05:00:56 +00:00
|
|
|
k=0;
|
|
|
|
if (hx < 0x00100000) { /* x < 2**-1022 */
|
|
|
|
if (((hx&0x7fffffff)|lx)==0)
|
|
|
|
return -two54/zero; /* log(+-0)=-inf */
|
|
|
|
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
|
|
|
|
k -= 54; x *= two54; /* subnormal number, scale up x */
|
1994-08-19 09:40:01 +00:00
|
|
|
GET_HIGH_WORD(hx,x);
|
2011-10-15 05:00:56 +00:00
|
|
|
}
|
1994-08-19 09:40:01 +00:00
|
|
|
if (hx >= 0x7ff00000) return x+x;
|
|
|
|
k += (hx>>20)-1023;
|
2011-03-07 03:11:27 +00:00
|
|
|
hx &= 0x000fffff;
|
|
|
|
i = (hx+0x95f64)&0x100000;
|
|
|
|
SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */
|
|
|
|
k += (i>>20);
|
|
|
|
y = (double)k;
|
|
|
|
f = __kernel_log(x);
|
|
|
|
hi = x = x - 1;
|
|
|
|
SET_LOW_WORD(hi,0);
|
|
|
|
lo = x - hi;
|
|
|
|
z = y*log10_2lo + (x+f)*ivln10lo + (lo+f)*ivln10hi + hi*ivln10hi;
|
1994-08-19 09:40:01 +00:00
|
|
|
return z+y*log10_2hi;
|
|
|
|
}
|