lgamma(x)函数详解

首页 / C++入门教程 / lgamma(x)函数详解

lgamma()函数计算传递给该函数的参数的gamma函数的对数。

假设数字为 x :

C++ Math lgamma() function

lgamma - 语法

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

lgamma - 参数

x :这是一个浮点值。

lgamma - 返回值

它返回值为x的伽马函数的对数。

参数 返回值
x= 1 or x=2 0
x= ±0 +∞
x= -ve integer or ±∞ +∞
x= nan nan

lgamma - 例子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值。

lgamma - 例子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()返回+∞。

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()返回+∞。

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。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

10x程序员工作法 -〔郑晔〕

架构实战案例解析 -〔王庆友〕

MySQL 必知必会 -〔朱晓峰〕

PyTorch深度学习实战 -〔方远〕

Kubernetes入门实战课 -〔罗剑锋〕

结构学习力 -〔李忠秋〕

结构沟通力 -〔李忠秋〕

Rust 语言从入门到实战 -〔唐刚〕

工程师个人发展指南 -〔李云〕

好记忆不如烂笔头。留下您的足迹吧 :)