C Math log1p() Function
Example
Return the natural logarithm of 1 + x:
printf("%f\n", log1p(0));
printf("%f", log1p(1));
Definition and Usage
The log1p() function returns the natural logarithm of 1 + x.
It gives the same result as log(1 + x), but it is more precise when x is very close to 0.
The log1p() function is defined in the <math.h> header file.
Tip: expm1() does the opposite. See also log().
Syntax
double log1p(double x);
There are also versions for float and long double values: log1pf() and log1pl().
Parameter Values
| Parameter | Description |
|---|---|
| x | Required. A number bigger than -1. |
Technical Details
| Returns: | A double value with the natural logarithm of 1 + x. |
|---|
Related Pages
Read more about math in our C Math Tutorial.