lgamma() 函数计算传递给函数的参数的伽马函数的对数。
假设一个数字是 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。
相关用法
- C++ Math log2()用法及代码示例
- C++ Math log()用法及代码示例
- C++ Math log10()用法及代码示例
- C++ Math logb()用法及代码示例
- C++ Math llround()用法及代码示例
- C++ Math less()用法及代码示例
- C++ Math lround()用法及代码示例
- C++ Math log1p()用法及代码示例
- C++ Math lrint()用法及代码示例
- C++ Math llrint()用法及代码示例
- C++ Math scalbn()用法及代码示例
- C++ Math acosh()用法及代码示例
- C++ Math asinh()用法及代码示例
- C++ Math isgreater()用法及代码示例
- C++ Math fabs()用法及代码示例
- C++ Math islessgreater()用法及代码示例
- C++ Math nearbyint()用法及代码示例
- C++ Math tan()用法及代码示例
- C++ Math nextafter()用法及代码示例
- C++ Math fdim()用法及代码示例
注:本文由纯净天空筛选整理自 C++ Math lgamma()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。