log10(x)函数详解

首页 / C++入门教程 / log10(x)函数详解

该函数计算给定数字的通用算法(以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。

链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-log10-function.html

来源:LearnFk无涯教程网

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)。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Android开发高手课 -〔张绍文〕

浏览器工作原理与实践 -〔李兵〕

Swift核心技术与实战 -〔张杰〕

研发效率破局之道 -〔葛俊〕

分布式技术原理与算法解析 -〔聂鹏程〕

接口测试入门课 -〔陈磊〕

检索技术核心20讲 -〔陈东〕

容器实战高手课 -〔李程远〕

后端工程师的高阶面经 -〔邓明〕

好记忆不如烂笔头。留下您的足迹吧 :)