无涯教程-log10(x)函数

156 阅读2分钟

该函数计算给定数字的通用算法(以10为底)。

假设数字是" x":

log10x = log10(x);

log10 - 语法

float log10(float x);
double log10(double x);
long double log10(long double x);
double log10(integral x);

Note: return_type可以是float,double或long double。

log10 - 参数

x :要计算其常用对数的值。

log10 - 返回值

以下是给定数字的返回值:

参数(x) 返回值
x>1 Positive
x=1 0
1>x>0 Negative
x=0 -infinity
x<0 Not a Number

log10 - 例子1

让我们看一个简单的示例,当x的值大于1时。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    int x=5;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"Log value of x is : "<<log10(x);
    return 0;
}

输出:

Value of x is : 5
Log value of x is : 0.69897

在此示例中,x的值为5。因此,函数log10()返回正值,即0.69。

log10 - 例子2

让我们看一个简单的例子,当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<<"Log value of x is : "<<log10(x);
    return 0;
}

输出:

Value of x is : 1
Log value of x is : 0

在此示例中,x的值为1。因此,函数log10()返回值零。

log10 - 例子3

让我们看一个简单的例子,当x的值为0.3时。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    float x=0.3;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"Log value of x is : "<<log10(x);
    return 0;
}

输出:

Value of x is : 0.3
Log value of x is : -0.522879

在此示例中,x的值为0.3。因此,函数log10()返回负值,即-0.52。

log10 - 例子4

让我们看一个简单的例子,当x的值为零时。

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    int x=0;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"Log value of x is : "<<log10(x);
    return 0;
}

输出:

Value of x is : 0
Log value of x is : -inf

在此示例中,x的值为零。因此,函数log10()返回负无穷大值。

log10 - 例子5

让我们看一个简单的例子,当x的值为-4时

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    float x= -4;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"Log value of x is : "<<log10(x);
    return 0;
}

输出:

Value of x is : -4
Log value of x is : nan

在此的示例x的值为-4。因此,函数log10()返回Not Number(nan)。

参考链接

www.learnfk.com/c++/cpp-mat…