17 * Returns the base 2 logarithm of x.
19 * The argument is separated into its exponent and fractional
20 * parts. If the exponent is between -1 and +1, the base e
21 * logarithm of the fraction is approximated by
23 * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x).
25 * Otherwise, setting z = 2(x-1)/x+1),
27 * log(x) = z + z**3 P(z)/Q(z).
34 * arithmetic domain # trials peak rms
35 * IEEE exp(+-88) 100000 1.1e-7 2.4e-8
36 * IEEE 0.5, 2.0 100000 1.1e-7 3.0e-8
38 * In the tests over the interval [exp(+-88)], the logarithms
39 * of the random arguments were uniformly distributed.
43 * log singularity: x = 0; returns MINLOGF/log(2)
44 * log domain: x < 0; returns MINLOGF/log(2)
48 Cephes Math Library Release 2.2: June, 1992
49 Copyright 1984, 1992 by Stephen L. Moshier
50 Direct inquiries to 30 Frost Street, Cambridge, MA 02140
54 static char fname[] = {"log2"};
56 /* Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)
57 * 1/sqrt(2) <= x < sqrt(2)
72 #define LOG2EA 0.44269504088896340735992
73 #define SQRTH 0.70710678118654752440
74 extern float MINLOGF, LOGE2F;
77 float frexpf(float, int *), polevlf(float, float *, int);
81 float frexpf(), polevlf();
95 mtherr( fname, SING );
97 mtherr( fname, DOMAIN );
98 return( MINLOGF/LOGE2F );
101 /* separate mantissa from exponent */
105 /* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */
118 y = x * ( z * polevlf( x, P, 8 ) );
119 y = y - 0.5 * z; /* y - 0.5 * x**2 */
122 /* Multiply log of fraction by log2(e)
123 * and base 2 exponent by 1
127 * This sequence of operations is critical and it may
128 * be horribly defeated by some compiler optimizers.