C++ Math log10()
C++ Math log10()
该函数计算给定数字的通用算法(以10为底)。
Math 上:
假设数字为" x":
语法
float log10(float x);
double log10(double x);
long double log10(long double x);
double log10(integral x);
注意: return_type可以是float,double或long double。
参数
x : 要计算其常用对数的值。
返回值
以下是给定数字的返回vlaue:
参数(x) |
返回值 |
x> 1 |
正面 |
x = 1 |
0 |
1> x> 0 |
否定 |
x = 0 |
-无穷大 |
x <0 |
不是数字 |
示例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、
示例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()返回值零。
示例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、
示例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()返回负无穷大值。
示例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)。