Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: PowerPC Numerics / Part 2 - The PowerPC Numerics C Implementation
Chapter 10 - Transcendental Functions /


log2

You can use the log2 function to compute the binary logarithm of a real number.

double_t log2 (double_t x);
x
Any positive floating-point number.
DESCRIPTION
The log2 function returns the binary (base 2) logarithm of its argument.

log2(x) =log2x = y such that x = 2y

The exp2 function performs the inverse operation.

EXCEPTIONS
When x is finite and nonzero, the result of log2(x) might raise one of the following exceptions:

  • inexact (for all finite, nonzero values of x other than +1)
  • invalid (when x is negative)

SPECIAL CASES
Table 10-17 shows the results when the argument to the log2 function is a zero, a NaN, or an Infinity, plus other special cases for the log2 function.
Special cases for the log2 function
OperationResultExceptions raised
log2(x) for x < 0NaNInvalid
log2(+1) +0None
log2(+0) - Divide-by-zero
log2(-0) - Divide-by-zero
log2(NaN) NaNNone[38]
log2(+ ) + None
log2(- ) NaNInvalid

EXAMPLES
z = log2(+1.0);   /* z = +0 because 20 = 1 */
z = log2(2.0);    /* z = 1 because 21 = 2. The inexact exception 
                     is raised. */
z = log2(-1.0);   /* z = NAN because negative arguments are not 
                     allowed. The invalid exception is raised. */

[38] If the NaN is a signaling NaN, the invalid exception is raised.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996