预订演示
前页 后页

log2

Base 2 logarithm.

SYNOPSIS:

double x, y, log2();
y = log2(x);

DESCRIPTION:

Returns the base 2 logarithm of x.

The argument is separated into its exponent and fractional parts.  If the exponent is between -1 and +1, the base e logarithm of the fraction is approximated by:

     log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x).

Otherwise, setting  z = 2(x-1)/x+1),

     log(x) = z + z**3 P(z)/Q(z).


ACCURACY:
                      Relative error:
arithmetic   domain     # trials      peak         rms
    IEEE      0.5, 2.0    30000       2.0e-16     5.5e-17
    IEEE      exp(+-700)  40000       1.3e-16     4.6e-17

In the tests over the interval [exp(+-700)], the logarithms of the random arguments were uniformly distributed.

ERROR MESSAGES:

singularity:  x = 0; returns -INFINITY
domain:       x < 0; returns NAN