當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C++ Math tgamma()用法及代碼示例

tgamma() 函數計算傳遞給函數的參數的伽馬函數。

假設一個數字是 x:

C++ Math tgamma() function

用法

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

參數

x: 它是一個浮點值。

返回值

它返回 x 的伽馬函數值。

參數 返回值
x = ±0 ±∞
x = -ve nan
x = -∞ nan
x = +∞ +∞
x = 南 nan

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

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

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

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

例 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。






相關用法


注:本文由純淨天空篩選整理自 C++ Math tgamma()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。