C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Math log()

C++ Math log()

该函数用于查找给定数字的自然对数(base-e对数)。

Math 上:

假设" x"是给定的数字:
logex = log(x);

语法

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

参数

x : 这是要计算其自然对数的值。

返回值

以下是给定数字的返回vlaue:
参数(x) 返回值
x> 1 正面
x = 1 0
1> x> 0 否定
x = 0 -infinty
x <0 不是数字(南)

示例1

让我们看一个简单的示例,当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 : "<<log(x);
    return 0;
}
输出:
Value of x is : 1
Log value of x is : 0
在此示例中,x的值为1、因此,函数log()返回正值,即0。

示例2

我们来看另一个简单的例子
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    int x=3;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"Log value of x is : "<<log(x);
    return 0;
}
输出:
Value of x is : 3
Log value of x is : 1.09861
在此示例中,x的值为3、因此,函数log()返回正值,即1.09861

示例3

看到一个简单的示例,当x的值为-0.5时。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    float x=-0.5;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"Log value of x is : "<<log(x);
    return 0;
}
输出:
Value of x is :-0.5
Log value of x is : nan
在此示例中,x的值为-0.5、因此,函数log()返回Not a Number(nan)。

示例4

让我们看一个简单的示例,当x的值为0时。
#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 : "<<log(x);
    return 0;
}
输出:
clValue of x is : 0
Log value of x is :-inf
在此示例中,x的值为-1、因此,函数log()返回nan(Not a Number)。

示例5

让我们看一个简单的示例,当x的值为0.8时。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
    float x=0.8;
    std::cout << "Value of x is : " <<x <<std::endl;
    cout<<"Log value of x is : "<<log(x);
    return 0;
}
输出:
Value of x is : 0.8
Log value of x is :-0.223144
在此示例中,x的值为0.8、因此,函数log()返回负值,即-0.22

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4