Base 10 logarithm function.
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.
Definition at line 93 of file log10.c.
References ivln10, log(), log10_2hi, log10_2lo, two54, and zero.
Referenced by DecimalSystem::GetText(), and RealNumber::Log10().
102 if (hx < 0x00100000) {
103 if (((hx&0x7fffffff)|lx)==0)
105 if (hx<0)
return (x-x)/
zero;
110 if (hx >= 0x7ff00000)
return x+x;
112 i = ((uint32_t)k&0x80000000)>>31;
113 hx = (hx&0x000fffff)|((0x3ff-i)<<20);
#define GET_HIGH_WORD(i, d)
Get the more significant 32 bit int from a double.
#define EXTRACT_WORDS(ix0, ix1, d)
Get two 32 bit ints from a double.
static const double two54
static const double log10_2hi
static const double ivln10
#define SET_HIGH_WORD(d, v)
Set the more significant 32 bits of a double from an int.
double log(double x)
Natural logarithm function (base e)
static const double log10_2lo