📜  C++ log10()

📅  最后修改于: 2020-09-25 07:49:31             🧑  作者: Mango

C++中的log10() 函数返回参数的公共对数(以10为底的对数)。

此函数在头文件中定义。

[Mathematics] log10x = log10(x) [In C++ Programming]

log10()原型[从C++ 11标准开始]

double log10 (double x);
float log10 (float x);
long double log10 (long double x);
double log10 (T x);  // For integral type

log10()参数

log10() 函数采用范围为[0,∞]的单个必需参数。

如果该值小于0,则log10()返回NaN (非数字)。

log10()返回值

log10() 函数返回数字的以10为底的对数。

Parameter (x) Return VALUE
x > 1 Positive
x = 1 0
0 > x > 1 Negative
x = 0 -∞ (- infinity)
x < 0 nan (Not a Number)

示例1:log10()如何工作?

#include 
#include 
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

示例2:带有整数类型的log10()

#include 
#include 
using namespace std;

int main ()
{
    int x = 2;
    double result;

    result = log10(x);
    cout << "log10(x) = " << result << endl;
    
    return 0;
}

运行该程序时,输出为:

log10(x) = 0.30103