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

C++ Math lgamma()

C++ Math lgamma()

lgamma()函数计算传递给该函数的参数的gamma函数的对数。
假设一个数字是 x :

语法

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

参数

x : 它是浮点值。

返回值

它返回值为x的伽马函数的对数。
参数 返回值
x = 1或x = 2 0
x =±0 +∞
x =-ve整数或±∞ +∞
x = nan nan

示例1

让我们看一下x值为2时的简单示例。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     int x=2;
     cout<<"Value of x is : "<<x<<'\n';
     cout<<"lgamma(x) :"<<lgamma(x);
     return 0;
}
输出:
Value of x is : 2
lgamma(x) :0
在上面的示例中,x的值为2、因此,函数lgamma()返回0值。

示例2

让我们看看x的值为0时的简单示例。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     int x=0;
     cout<<"Value of x is : "<<x<<'\n';
     cout<<"lgamma(x) : "<<lgamma(x);
     return 0;
}
输出:
Value of x is : 0
lgamma(x) : inf
在上面的示例中,x的值为零。因此,函数lgamma()返回+∞。

示例3

让我们看一个简单的示例,当x的值为负整数时。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     int x=-5;
     cout<<"Value of x is : "<<x<<'\n';
     cout<<"lgamma(x) : "<<lgamma(x);
     return 0;
}
输出:
Value of x is :-5
lgamma(x) : inf
在上面的示例中,x的值为负整数。因此,函数lgamma()返回+∞。

示例4

让我们看一下x值为nan时的简单示例。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     float x=sqrt(-6);
     cout<<"Value of x is : "<<x<<'\n';
     cout<<"lgamma(x) :"<<lgamma(x);
     return 0;
}
输出:
Value of x is :-nan
lgamma(x) :-nan
在上面的示例中,x的值为nan。因此,函数lgamma()返回nan。

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