tgamma(x)函数详解

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

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

假设数字是 x:

C++ Math tgamma() function

tgamma - 语法

float tgamma(float x);
double tgamma(double x);
long double tgamma(long double x);
double tgamma(double x);

tgamma - 参数

x :这是一个浮点值。

tgamma - 返回值

它返回x的伽玛函数值。

参数 返回值
x = ±0 ±∞
x = -ve nan
x = -∞ nan
x = +∞ +∞
x = nan nan

tgamma - 例子1

让我们看一个简单的例子,当x的值为零时。

#include <iostream>  
#include<math.h>  
using namespace std;  
int main()  
{  
     float x= 0.0;  
     cout<<"Value of x is : "<<x<<'\n';  
     cout<<"tgamma(x) : "<<tgamma(x);  
     return 0;
 }  

输出:

Value of x is : 0
tgamma(x) : inf

在上面的示例中,x的值为零,因此函数tgamma()返回+∞。

tgamma - 例子2

让我们看一个简单的例子,当x的值为负数时。

#include <iostream>  
#include<math.h>  
using namespace std;  
int main()  
{  
     int x= -6;  
     cout<<"Value of x is : "<<x<<'\n';  
     cout<<"tgamma(x) : "<<tgamma(x);  
     return 0;  
}  

输出:

Value of x is : -6
tgamma(x) : nan

在上面的示例中,x的值为负整数。因此,函数tgamma()返回nan。

链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-tgamma-function.html

来源:LearnFk无涯教程网

tgamma - 例子3

让我们看一下x的值为-∞时的简单示例。

#include <iostream>  
#include<math.h>  
using namespace std;  
int main()  
{  
     float x= -9.0/0.0;  
     cout<<"Value of x is : "<<x<<'\n';  
     cout<<"tgamma(x): "<<tgamma(x);  
     return 0;  
}  

输出:

Value of x is : -inf
tgamma(x): nan

在上面的示例中,x-∞的值。因此,函数tgamma()返回nan。

tgamma - 例子4

让我们看一个简单的例子,当的值为+∞时。

#include <iostream>  
#include<math.h>  
using namespace std;  
int main()  
{  
     float x= 7.8/0.0;  
     cout<<"Value of x is : "<<x<<'\n';  
     cout<<"tgamma(x) : "<<tgamma(x);  
     return 0;  
}  

输出:

Value of x is : inf
tgamma(x) : inf

在上面的示例中,x的值为+∞。因此,函数tgamma()返回+∞。

tgamma - 例子5

让我们看一下x的值为nan时的简单示例。

#include <iostream>  
#include<math.h>  
using namespace std;  
int main()  
{  
     float x= 0.0/0.0;  
     cout<<"Value of x is : "<<x<<'\n';  
     cout<<"tgamma(x) : "<<tgamma(x);  
    return 0;  
}  

输出:

Value of x is : -nan
tgamma(x) : -nan

在上面的示例中,x的值为nan。因此,函数tgamma()返回nan。

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

技术教程推荐

从0开始学游戏开发 -〔蔡能〕

玩转Git三剑客 -〔苏玲〕

大规模数据处理实战 -〔蔡元楠〕

说透中台 -〔王健〕

Django快速开发实战 -〔吕召刚〕

深入浅出分布式技术原理 -〔陈现麟〕

现代React Web开发实战 -〔宋一玮〕

JavaScript进阶实战课 -〔石川〕

快速上手C++数据结构与算法 -〔王健伟〕

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