📅  最后修改于: 2020-09-25 07:48:24             🧑  作者: Mango
此函数在
[Mathematics] logex = log(x) [In C++ Programming]
double log (double x);
float log (float x);
long double log (long double x);
double log (T x); // For integral type
log() 函数采用[0,∞]范围内的单个必需参数。
如果该值小于零,则log()返回NaN
(非数字)。
log() 函数返回数字的自然对数。
Parameter (x) | Return VALUE |
---|---|
x > 1 | Positive |
x = 1 | 0 |
0 > x > 1 | Negative |
x = 0 | -∞ (- infinity) |
x < 0 | NaN (Not a Number) |
#include
#include
using namespace std;
int main ()
{
double x = 13.056, result;
result = log (x);
cout << "log(x) = " << result << endl;
x = -3.591;
result = log (x);
cout << "log(x) = " << result << endl;
return 0;
}
运行该程序时,输出为:
log(x) = 2.56925
log(x) = nan
#include
#include
using namespace std;
int main ()
{
int x = 2;
double result;
result = log (x);
cout << "log(x) = " << result << endl;
return 0;
}
运行该程序时,输出为:
log(x) = 0.693147