C ++中的log10()函数返回参数的公共对数(以10为底的对数)。
此函数在<cmath>头文件中定义。
log10x = log10(x)
double log10 (double x); float log10 (float x); long double log10 (long double x); double log10 (T x); //为整型
log10()函数采用范围为[0,∞]的单个必需参数。
如果该值小于0,则log10()返回NaN(非数字)。
log10()函数返回数字的以10为底的对数。
参数(x) | 返回VALUE |
---|---|
x> 1 | Positive |
x = 1 | 0 |
0> x> 1 | Negative |
x = 0 | -∞(-无穷大) |
x <0 | nan (不是数字) |
#include <iostream> #include <cmath> using namespace std; int main () { double x = 13.056, result; result = log10(x); cout << "log10(x) = " << result << endl; x = -3.591; result = log10(x); cout << "log10(x) = " << result << endl; return 0; }
运行该程序时,输出为:
log10(x) = 1.11581 log10(x) = nan
#include <iostream> #include <cmath> using namespace std; int main () { int x = 2; double result; result = log10(x); cout << "log10(x) = " << result << endl; return 0; }
运行该程序时,输出为:
log10(x) = 0.30103