Important: The information in this document is obsolete and should not be used for new development.
log1p
You can use thelog1p
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
Thelog1p
function computes the natural logarithm of 1 plus its argument.such that
For small numbers, use the function call
log1p(x)
instead of the function calllog(1 + x)
. The calllog1p(x)
produces a more exact result because it avoids the roundoff error that might occur when the expression1 + x
is computed.EXCEPTIONS
When x is finite and nonzero, the result of 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 thelog1p
function is a zero, a NaN, or an Infinity, plus other special cases for thelog1p
function.
Special cases for the log1p
functionOperation Result Exceptions raised for x < -1 NaN Invalid - Divide-by-zero +0 None -0 None NaN None[37] + None NaN Invalid 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.