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 /


log1p

You can use the log1p function to compute the natural logarithm of 1 plus a real number.

double_t log1p (double_t x);
x
Any floating-point number greater than -1.
DESCRIPTION
The log1p function computes the natural logarithm of 1 plus its argument.

log1p(x) = loge(x+1) = ln(x+1) = y such that 1+x = 10y

For small numbers, use the function call log1p(x) instead of the function call log(1 + x). The call log1p(x) produces a more exact result because it avoids the roundoff error that might occur when the expression 1 + x is computed.

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

  • inexact (for all finite, nonzero values of x > -1)
  • invalid (when x is less than -1)
  • divide-by-zero (when x is -1)

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

EXAMPLES
z = log1p(-1.0);  /* z = log(0) = -INFINITY. The divide-by-zero 
                     and inexact exceptions are raised. */
z = log1p(0.0);   /* z = log(1) = 0.0 because e0 = 1. */
z = log1p(-2.0);  /* z = log(-1) = NAN because logarithms of 
                     negative numbers are not allowed. The 
                     invalid exception is raised. */

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

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996