English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C ++in the log1p() function takes the parameter x and returns x + 1the natural logarithm (logarithm with base e).
This function calculates<cmath>defined in the header file.
log(x+1) = log1p(x)
double log1p(double x); float log1p(float x); long double log1p(long double x); double log1p(T x); //for integer
log1p() function has only one parameter and returns a value of type double, float, or long double.
log1p() function uses a single mandatory parameter, ranging from[-1, ∞].
if the value is less than-1, then log1p() returns NaN (Not a Number).
log1p() function returns1the natural logarithm of the parameter plus the given parameter.
Parameter (x) | Return value |
---|---|
x > 0 | Positive |
x = 0 | Zero |
-1> x > 0 | Negative |
x = -1 | -∞ (-infinity) |
x <-1 | NaN (Not a Number) |
#include <iostream> #include <cmath> using namespace std; int main () { double x = 21.371, result; result = log1p(x); cout << "log1p(x) = " << result << endl; return 0; }
When running the program, the output is:
log1p(x) = 3.10777
#include <iostream> #include <cmath> using namespace std; int main () { double result = int x = 147; result = log1p(x); cout << "log1p(x) = " << result << endl; return 0; }
When running the program, the output is:
log1p(x) = 4.99721