該函數計算給定數字加一的自然對數。
假設一個數字是 'x':
log1p(x) = log(1+x);
用法
float log1p(float x);
double log1p(double x);
long double log1p(long double x);
double log1p(integral x);
注意:return_type 可以是 float、double 或 long double。
參數
x:要計算哪個對數的值。
返回值
參數 | 返回值 |
---|---|
x>0 | Positive |
x=0 | zero |
0>x>-1 | Negative |
x= -1 | -無窮大 |
x<-1 | 不是數字(nan) |
例子1
當 x 的值大於零時,讓我們看一個簡單的例子。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x=10;
std::cout << "Value of x is:" <<x <<std::endl;
cout<<"log1p(x) = "<<log1p(x);
return 0;
}
輸出:
Value of x is:10 log1p(x) = 2.3979
在此示例中,log1p() 函數計算 x 大於零時的對數值。
例子2
讓我們看一個簡單的例子,當 x 的值為零時
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x=0;
std::cout << "Value of x is:" <<x <<std::endl;
cout<<"log1p(x) = "<<log1p(x);
return 0;
}
輸出:
Value of x is:0 log1p(x) = 0
在本例中,log1p() 函數計算 x 的值為零時的對數值。
例子3
當 x 的值小於零時,讓我們看一個簡單的例子。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x= -0.5;
std::cout << "Value of x is:" <<x <<std::endl;
cout<<"log1p(x) = "<<log1p(x);
return 0;
}
輸出:
Value of x is:-0.5 log1p(x) = -0.693147
在本例中,log1p() 函數計算 x 小於零時的對數值。
示例 4
讓我們看一個簡單的例子,當 x 的值為 -1 時。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x= -1;
std::cout << "Value of x is:" <<x <<std::endl;
cout<<"log1p(x) = "<<log1p(x);
return 0;
}
輸出:
Value of x is:-1 log1p(x) = -inf
在本例中,log1p() 函數計算 x 的值為 -1 時的對數值。
例 5
讓我們看一個簡單的例子,當 x 的值小於 -1 時。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x= -3;
std::cout << "Value of x is:" <<x <<std::endl;
cout<<"log1p(x) = "<<log1p(x);
return 0;
}
輸出:
Value of x is:-3 log1p(x) = -nan
在本例中,log1p() 函數計算 x 的值小於 -1 時的對數值。
相關用法
- C++ Math log10()用法及代碼示例
- C++ Math log2()用法及代碼示例
- C++ Math log()用法及代碼示例
- C++ Math logb()用法及代碼示例
- C++ Math llround()用法及代碼示例
- C++ Math less()用法及代碼示例
- C++ Math lgamma()用法及代碼示例
- C++ Math lround()用法及代碼示例
- C++ Math lrint()用法及代碼示例
- C++ Math llrint()用法及代碼示例
- C++ Math scalbn()用法及代碼示例
- C++ Math acosh()用法及代碼示例
- C++ Math asinh()用法及代碼示例
- C++ Math isgreater()用法及代碼示例
- C++ Math fabs()用法及代碼示例
- C++ Math islessgreater()用法及代碼示例
- C++ Math nearbyint()用法及代碼示例
- C++ Math tan()用法及代碼示例
- C++ Math nextafter()用法及代碼示例
- C++ Math fdim()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Math log1p()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。