log1p
Compute the base-e logarithm of (1+x), that is, ln(1+x).
Interface Definition
C interface:
float log1pf(float x);
double log1p(double x);
long double log1pl(long double x);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of the input data. |
Input |
Return Value
- The base-e logarithm y of 1+x is returned. y ∈ (-INF, +INF)
- If input x is +0, the return value is +0.
- If input x is -0, the return value is -0.
- If input x is -1, the return value is -∞.
- If input x is +∞, the return value is +∞.
- If input x is less than -1, the return value is NaN.
- If input x is NaN, the return value is NaN.
Dependency
C: "km.h"
Example
C interface:
// typical usage
double x1 = 0.0, x2 = -0.0, x3 = -1, x4 = -2;
// special handing
double a = INFINITY, b = -INFINITY, c = NAN;
// print result
printf("log1p(0.0) = %.15f\n", log1p(x1));
printf("log1p(-0.0) = %.15f\n", log1p(x2));
printf("log1p(-1) = %.15f\n", log1p(x3));
printf("log1p(-2) = %.15f\n", log1p(x4));
printf("log1p(INFINITY) = %.15f\n", log1p(a));
printf("log1p(-INFINITY) = %.15f\n", log1p(b));
printf("log1p(NAN) = %.15f\n", log1p(c));
/*
* log1p(0.0) = 0.000000000000000
* log1p(-0.0) = -0.000000000000000
* log1p(-1) = -inf
* log1p(-2) = nan
* log1p(INFINITY) = inf
* log1p(-INFINITY) = nan
* log1p(NAN) = nan
*
* */
Parent topic: Exponential and Logarithmic Functions