std::erf, std::erff, std::erfl
提供: cppreference.com
<tbody>
</tbody>
∫arg
0e-t2
dt
)
| ヘッダ <cmath> で定義
|
||
float erf ( float arg ); float erff( float arg ); |
(1) | (C++11以上) |
double erf ( double arg ); |
(2) | (C++11以上) |
long double erf ( long double arg ); long double erfl( long double arg ); |
(3) | (C++11以上) |
double erf ( 整数型 arg ); |
(4) | (C++11以上) |
引数
| arg | - | 浮動小数点または整数型の値 |
戻り値
エラーが発生しなければ、 arg の誤差関数の値、つまり
| 2 |
| √π |
0e-t2
dt
が返されます。
アンダーフローによる値域エラーが発生した場合、 (丸めた後の) 正しい結果、つまり
| 2*arg |
| √π |
が返されます。
エラー処理
math_errhandling で規定されている通りにエラーが報告されます。
処理系が IEEE 浮動小数点算術 (IEC 60559) をサポートしている場合、
- 引数が ±0 であれば、 ±0 が返されます。
- 引数が ±∞ であれば、 ±1 が返されます。
- 引数が NaN であれば、 NaN が返されます。
ノート
|arg| < DBL_MIN*(sqrt(π)/2) の場合、アンダーフローが保証されます。
| x |
| σ√2 |
は、誤差が標準偏差 σ の正規分布である測定値の、平均値からの距離が x より小さい確率です。
例
以下の例は標準変量が区間 (x1, x2) 上である確率を計算します
Run this code
#include <iostream>
#include <cmath>
#include <iomanip>
double phi(double x1, double x2)
{
return (std::erf(x2/std::sqrt(2)) - std::erf(x1/std::sqrt(2)))/2;
}
int main()
{
std::cout << "normal variate probabilities:\n"
<< std::fixed << std::setprecision(2);
for(int n=-4; n<4; ++n)
std::cout << "[" << std::setw(2) << n << ":" << std::setw(2) << n+1 << "]: "
<< std::setw(5) << 100*phi(n, n+1) << "%\n";
std::cout << "special values:\n"
<< "erf(-0) = " << std::erf(-0.0) << '\n'
<< "erf(Inf) = " << std::erf(INFINITY) << '\n';
}
出力:
normal variate probabilities:
[-4:-3]: 0.13%
[-3:-2]: 2.14%
[-2:-1]: 13.59%
[-1: 0]: 34.13%
[ 0: 1]: 34.13%
[ 1: 2]: 13.59%
[ 2: 3]: 2.14%
[ 3: 4]: 0.13%
special values:
erf(-0) = -0.00
erf(Inf) = 1.00
関連項目
(C++11)(C++11)(C++11) |
相補誤差関数を計算します (関数) |
erf の C言語リファレンス
|
外部リンク
Weisstein, Eric W. "Erf." From MathWorld--A Wolfram Web Resource.