该函数计算给定数字的通用算法(以10为底)。
假设数字是" x":
log10x = log10(x);
float log10(float x); double log10(double x); long double log10(long double x); double log10(integral x);
x :要计算其常用对数的值。
以下是给定数字的返回值:
参数(x) | 返回值 |
---|---|
x>1 | Positive |
x=1 | 0 |
1>x>0 | Negative |
x=0 | -infinity |
x<0 | Not a Number |
让我们看一个简单的示例,当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。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-log10-function.html
来源:LearnFk无涯教程网
让我们看一个简单的例子,当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()返回值零。
让我们看一个简单的例子,当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。
让我们看一个简单的例子,当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()返回负无穷大值。
让我们看一个简单的例子,当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)。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)