Namespaces
Variants

tgamma, tgammaf, tgammal

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
tgamma
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
ヘッダー <math.h> で定義
float tgammaf ( float arg ) ;
(1) (C99以降)
double tgamma ( double arg ) ;
(2) (C99以降)
long double tgammal ( long double arg ) ;
(3) (C99以降)
ヘッダー <tgmath.h> で定義
#define tgamma( arg )
(4) (C99以降)
1-3) arg ガンマ関数 を計算します。
4) 型総称マクロ: arg long double 型の場合、 tgammal が呼び出される。それ以外の場合、 arg が整数型または double 型の場合、 tgamma が呼び出される。それ以外の場合、 tgammaf が呼び出される。

目次

パラメータ

arg - 浮動小数点値

戻り値

エラーが発生しない場合、 arg のガンマ関数の値、すなわち
0
t arg-1
e -t d t
が返されます。

定義域エラーが発生した場合、実装定義の値(NaNがサポートされている場合はNaN)が返されます。

極エラーが発生した場合、 ± HUGE_VAL ±HUGE_VALF または ±HUGE_VALL が返されます。

オーバーフローによる範囲エラーが発生した場合、 ±HUGE_VAL ±HUGE_VALF または ±HUGE_VALL が返されます。

アンダーフローによる範囲エラーが発生した場合、正しい値(丸め後)が返されます。

エラーハンドリング

エラーは math_errhandling で指定された通りに報告されます。

arg がゼロまたはゼロより小さい整数の場合、極エラーまたは定義域エラーが発生する可能性があります。

IEEE浮動小数点演算(IEC 60559)がサポートされている場合:

  • 引数が±0の場合、±∞が返され、 FE_DIVBYZERO が発生します。
  • 引数が負の整数の場合、NaNが返され、 FE_INVALID が発生します。
  • 引数が-∞の場合、NaNが返され、 FE_INVALID が発生します。
  • 引数が+∞の場合、+∞が返されます。
  • 引数がNaNの場合、NaNが返されます。

注記

arg が自然数の場合、 tgamma ( arg ) arg - 1 の階乗です。多くの実装では、引数が十分に小さい整数の場合、正確な整数領域の階乗を計算します。

IEEE互換の型 double の場合、オーバーフローは 0 < x < 1 / DBL_MAX の場合、または x > 171.7 の場合に発生します。

POSIXは 引数がゼロの場合には極エラーが発生することを要求しますが、引数が負の整数の場合には定義域エラーが発生します。また、将来のバージョンでは負の整数引数に対する定義域エラーが極エラーに置き換えられる可能性があることも規定しています(その場合、これらのケースでの戻り値はNaNから±∞に変更されます)。

様々な実装において、非標準の関数 gamma が存在しますが、その定義は一貫していません。例えば、glibcと4.2BSD版の gamma lgamma を実行しますが、4.4BSD版の gamma tgamma を実行します。

#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
// #pragma STDC FENV_ACCESS ON
int main(void)
{
    printf("tgamma(10) = %f, 9!=%f\n", tgamma(10), 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9.0);
    printf("tgamma(0.5) = %f, sqrt(pi) = %f\n", tgamma(0.5), sqrt(acos(-1)));
    // 特殊値
    printf("tgamma(+Inf) = %f\n", tgamma(INFINITY));
    // エラー処理
    errno = 0; feclearexcept(FE_ALL_EXCEPT);
    printf("tgamma(-1) = %f\n", tgamma(-1));
    if (errno == ERANGE)
        perror("    errno == ERANGE");
    else
        if (errno == EDOM)   perror("    errno == EDOM");
    if (fetestexcept(FE_DIVBYZERO))
        puts("    FE_DIVBYZERO raised");
    else if (fetestexcept(FE_INVALID))
        puts("    FE_INVALID raised");
}

出力例:

tgamma(10) = 362880.000000, 9!=362880.000000
tgamma(0.5) = 1.772454, sqrt(pi) = 1.772454
tgamma(+Inf) = inf
tgamma(-1) = nan
    errno == EDOM: Numerical argument out of domain
    FE_INVALID raised

参考文献

  • C23規格 (ISO/IEC 9899:2024):
  • 7.12.8.4 tgamma関数群 (p: 250)
  • 7.25 総称型数学 <tgmath.h> (p: 373-375)
  • F.10.5.4 tgamma関数群 (p: 525)
  • C17規格 (ISO/IEC 9899:2018):
  • 7.12.8.4 tgamma関数群 (p: 250)
  • 7.25 総称数学 <tgmath.h> (p: 373-375)
  • F.10.5.4 tgamma関数群 (p: 525)
  • C11規格 (ISO/IEC 9899:2011):
  • 7.12.8.4 tgamma関数 (p: 250)
  • 7.25 総称数学 <tgmath.h> (p: 373-375)
  • F.10.5.4 tgamma関数 (p: 525)
  • C99規格 (ISO/IEC 9899:1999):
  • 7.12.8.4 tgamma関数 (p: 231)
  • 7.22 総称数学 <tgmath.h> (p: 335-337)
  • F.9.5.4 tgamma関数 (p: 462)

関連項目

(C99) (C99) (C99)
ガンマ関数の自然(底 e )対数を計算する
(関数)

外部リンク

Weisstein, Eric W. "Gamma Function." From MathWorld — A Wolfram Web Resource.
日本語訳:
Weisstein, Eric W. "ガンマ関数" MathWorld — Wolfram Webリソースより
翻訳内容: - "Gamma Function" → "ガンマ関数"(数学用語として標準的な訳語) - "From MathWorld — A Wolfram Web Resource." → "MathWorld — Wolfram Webリソースより"(自然な日本語表現に変換) - HTMLタグ、属性、スタイルは完全に保持 - 人名"Weisstein, Eric W."は翻訳せず保持