lgamma()函数计算传递给该函数的参数的gamma函数的对数。
假设数字为 x :
float lgamma(float x); double lgamma(double x); long double lgamma(long double x); double lgamma(integral x);
x :这是一个浮点值。
它返回值为x的伽马函数的对数。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-lgamma-function.html
来源:LearnFk无涯教程网
参数 | 返回值 |
---|---|
x= 1 or x=2 | 0 |
x= ±0 | +∞ |
x= -ve integer or ±∞ | +∞ |
x= nan | nan |
让我们看一个简单的例子,当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值。
让我们看一下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()返回+∞。
让我们看一下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()返回+∞。
让我们看一下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。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Python实战 · 从0到1搭建直播视频平台 -〔Barry〕