namespace std {
float lgamma(float x); // (1) C++11からC++20まで
double lgamma(double x); // (2) C++11からC++20まで
long double lgamma(long double x); // (3) C++11からC++20まで
floating-point-type
lgamma(floating-point-type x); // (4) C++23
constexpr floating-point-type
lgamma(floating-point-type x); // (4) C++26
double
lgamma(Integral x); // (5) C++11
constexpr double
lgamma(Integral x); // (5) C++26
float
lgammaf(float x); // (6) C++17
constexpr float
lgammaf(float x); // (6) C++26
long double
lgammal(long double x); // (7) C++17
constexpr long double
lgammal(long double x); // (7) C++26
}
概要
ガンマ関数 tgamma
) の絶対値の自然対数を求める。
- (1) :
float
に対するオーバーロード - (2) :
double
に対するオーバーロード - (3) :
long double
に対するオーバーロード - (4) : 浮動小数点数型に対するオーバーロード
- (5) : 整数型に対するオーバーロード (
double
にキャストして計算される) - (6) :
float
型規定 - (7) :
long double
型規定
戻り値
引数 x
のガンマ関数の絶対値の自然対数を返す。
備考
- C++11 以降では、処理系が IEC 60559 に準拠している場合(
std::numeric_limits<T>::is_iec559() != false
)、以下の規定が追加される。 - C++23では、(1)、(2)、(3)が(4)に統合され、拡張浮動小数点数型を含む浮動小数点数型へのオーバーロードとして定義された
- この関数はガンマ関数 (
tgamma
) がオーバーフローするような場合に使う。 具体例についてはガンマ関数の備考を参照のこと。
例
#include <cmath>
#include <iostream>
#include <limits>
int main() {
std::cout << std::fixed;
std::cout << "lgamma(-∞) = " << std::lgamma(-std::numeric_limits<double>::infinity()) << std::endl;
std::cout << "lgamma(-1) = " << std::lgamma(-1.0) << std::endl;
std::cout << "lgamma(0) = " << std::lgamma(0.0) << std::endl;
std::cout << "lgamma(0.5) = " << std::lgamma(0.5) << std::endl;
std::cout << "lgamma(1) = " << std::lgamma(1.0) << std::endl;
std::cout << "lgamma(+∞) = " << std::lgamma(std::numeric_limits<double>::infinity()) << std::endl;
}
14
#include <cmath>
#include <iostream>
#include <limits>
int main() {
std::cout << std::fixed;
std::cout << "lgamma(-∞) = " << std::lgamma(-std::numeric_limits<double>::infinity()) << std::endl;
std::cout << "lgamma(-1) = " << std::lgamma(-1.0) << std::endl;
std::cout << "lgamma(0) = " << std::lgamma(0.0) << std::endl;
std::cout << "lgamma(0.5) = " << std::lgamma(0.5) << std::endl;
std::cout << "lgamma(1) = " << std::lgamma(1.0) << std::endl;
std::cout << "lgamma(+∞) = " << std::lgamma(std::numeric_limits<double>::infinity()) << std::endl;
}
出力例
lgamma(-∞) = inf
lgamma(-1) = inf
lgamma(0) = inf
lgamma(0.5) = 0.572365
lgamma(1) = 0.000000
lgamma(+∞) = inf
バージョン
言語
- C++11
処理系
- Clang: 3.0 ✅
- GCC: 4.3.6 ✅
- ICC: ??
- Visual C++: ??
備考
特定の環境では、早期に constexpr
対応されている場合がある:
- GCC 4.6.1 以上
関連項目
- ガンマ関数
tgamma