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。