summaryrefslogtreecommitdiffstats
path: root/lib/msun
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2011-03-07 03:11:27 +0000
committerdas <das@FreeBSD.org>2011-03-07 03:11:27 +0000
commitc8691f6e6a0e57ecce0dc94678561826833214f4 (patch)
tree9b9903eb9f7f15c5406d5c4fd3327a96445326e8 /lib/msun
parent55e5832ebf71c5279994dae84bf74bc646ad717f (diff)
downloadFreeBSD-src-c8691f6e6a0e57ecce0dc94678561826833214f4.zip
FreeBSD-src-c8691f6e6a0e57ecce0dc94678561826833214f4.tar.gz
Convert log10() to use __kernel_log(), which is more accurate and simpler.
Diffstat (limited to 'lib/msun')
-rw-r--r--lib/msun/src/e_log10.c54
1 files changed, 16 insertions, 38 deletions
diff --git a/lib/msun/src/e_log10.c b/lib/msun/src/e_log10.c
index 7871b5e..135f0dc 100644
--- a/lib/msun/src/e_log10.c
+++ b/lib/msun/src/e_log10.c
@@ -14,45 +14,18 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-/* __ieee754_log10(x)
- * Return the base 10 logarithm of x
- *
- * Method :
- * Let log10_2hi = leading 40 bits of log10(2) and
- * log10_2lo = log10(2) - log10_2hi,
- * ivln10 = 1/log(10) rounded.
- * Then
- * n = ilogb(x),
- * if(n<0) n = n+1;
- * x = scalbn(x,-n);
- * log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x))
- *
- * Note 1:
- * To guarantee log10(10**n)=n, where 10**n is normal, the rounding
- * mode must set to Round-to-Nearest.
- * Note 2:
- * [1/log(10)] rounded to 53 bits has error .198 ulps;
- * log10 is monotonic at all binary break points.
- *
- * Special cases:
- * log10(x) is NaN with signal if x < 0;
- * log10(+INF) is +INF with no signal; log10(0) is -INF with signal;
- * log10(NaN) is that NaN with no signal;
- * log10(10**N) = N for N=0,1,...,22.
- *
- * Constants:
- * The hexadecimal values are the intended ones for the following constants.
- * The decimal values may be used, provided that the compiler will convert
- * from decimal to binary accurately enough to produce the hexadecimal values
- * shown.
+/*
+ * Return the base 10 logarithm of x. See k_log.c for details on the algorithm.
*/
#include "math.h"
#include "math_private.h"
+#include "k_log.h"
static const double
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
-ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
+ivln10hi = 4.34294481878168880939e-01, /* 0x3fdbcb7b, 0x15200000 */
+ivln10lo = 2.50829467116452752298e-11, /* 0x3dbb9438, 0xca9aadd5 */
log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
@@ -61,7 +34,7 @@ static const double zero = 0.0;
double
__ieee754_log10(double x)
{
- double y,z;
+ double f,hi,lo,y,z;
int32_t i,k,hx;
u_int32_t lx;
@@ -77,10 +50,15 @@ __ieee754_log10(double 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);
+ 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;
return z+y*log10_2hi;
}
OpenPOWER on IntegriCloud