C++ cmath log1p() Function
Example
Return the natural logarithm of 1 + x:
cout << log1p(0) << "\n";
cout << 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 <cmath> header file.
Tip: expm1() does the opposite. See also log().
Syntax
log1p(double x)
The function also works with float and long double values. Then it returns a value of the same type.
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 Math Tutorial.