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 / Logarithmic Functions


log

You can use the log function to compute the natural logarithm of a real number.

double_t log (double_t x);
x
Any positive floating-point number.
DESCRIPTION
The log function returns the natural (base e) logarithm of its argument.

log(x) = logex = lnx = y such that x = ey

The exp function performs the inverse (exponential) operation.

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

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

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

EXAMPLES
z = log(+1.0);    /* z = +0.0 because e0 = 1 */
z = log(-1.0);    /* z = NAN because negative arguments are not 
                     allowed. The invalid exception is raised. */


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

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996