函式
<cmath> <ctgmath>

tgamma

     double tgamma  (     double x);      float tgammaf (      float x);long double tgammal (long double x);
     double tgamma (     double x);      float tgamma (      float x);long double tgamma (long double x);     double tgamma (T x);           // additional overloads for integral types
計算伽馬函式
伽馬函式 返回 x伽馬函式值。

標頭檔案 <tgmath.h> 提供了此函式的型別通用宏版本。
此標頭檔案 (<cmath>) 中為整型提供了額外的過載:這些過載在計算前會有效地將 x 轉換為 double(為任何整型T 定義)。

引數

x
伽馬函式的引數。

返回值

x 的伽馬函式值。
如果 x 的量級太大,會發生上溢範圍錯誤。如果太小,可能會發生下溢範圍錯誤
如果 x 是零或函式呈漸近線的負整數,則可能導致定義域錯誤極點錯誤(或沒有錯誤,取決於具體實現)。

如果發生定義域錯誤
- 並且 math_errhandling 設定了 MATH_ERRNO:全域性變數 errno 會被設定為 EDOM
- 並且 math_errhandling 設定了 MATH_ERREXCEPT:將引發 FE_INVALID

如果發生範圍錯誤
- 並且 math_errhandling 設定了 MATH_ERRNO:全域性變數 errno 被設定為 ERANGE
- 並且 math_errhandling 設定了 MATH_ERREXCEPT:將引發 FE_OVERFLOWFE_UNDERFLOW

如果發生極點錯誤
- 並且 math_errhandling 設定了 MATH_ERRNO:全域性變數 errno 被設定為 ERANGE
- 並且 math_errhandling 設定了 MATH_ERREXCEPT:將引發 FE_DIVBYZERO

示例

1
2
3
4
5
6
7
8
9
10
11
12
/* tgamma example */
#include <stdio.h>      /* printf */
#include <math.h>       /* tgamma */

int main ()
{
  double param, result;
  param = 0.5;
  result = tgamma (param);
  printf ("tgamma(%f) = %f\n", param, result );
  return 0;
}

輸出

tgamma (0.500000) = 1.772454


另見