📅  最后修改于: 2020-09-25 07:50:49             🧑  作者: Mango
该函数在
[Mathematics] loge(x+1) = log1p(x) [In C++ Programming]
double log1p (double x);
float log1p (float x);
long double log1p (long double x);
double log1p (T x); // For integral type
log1p() 函数采用单个参数,并返回double
, float
或long double
类型的值。
log1p() 函数采用单个强制性参数,范围为[-1,∞]。
如果该值小于-1,则log1p()返回Nan
(非数字)。
log1p() 函数返回1的自然对数加上给定的参数。
Parameter (x) | Return Value |
---|---|
x > 0 | Positive |
x = 0 | Zero |
-1 > x > 0 | Negative |
x = -1 | -∞ (- infinity) |
x < -1 | NaN (Not a number) |
#include
#include
using namespace std;
int main ()
{
double x = 21.371, result;
result = log1p(x);
cout << "log1p(x) = " << result << endl;
return 0;
}
运行该程序时,输出为:
log1p(x) = 3.10777
#include
#include
using namespace std;
int main ()
{
double result;
int x = 147;
result = log1p(x);
cout << "log1p(x) = " << result << endl;
return 0;
}
运行该程序时,输出为:
log1p(x) = 4.99721