erf, erff, erfl
提供: cppreference.com
<tbody>
</tbody>
)
| ヘッダ <math.h> で定義
|
||
float erff( float arg ); |
(1) | (C99以上) |
double erf( double arg ); |
(2) | (C99以上) |
long double erfl( long double arg ); |
(3) | (C99以上) |
| ヘッダ <tgmath.h> で定義
|
||
#define erf( arg ) |
(4) | (C99以上) |
4) 型総称マクロ。
arg が long double 型の場合は erfl が呼ばれます。 そうでなく、 arg が整数型または double 型の場合は erf が呼ばれます。 そうでなければ erff が呼ばれます。引数
| arg | - | 浮動小数点値 |
戻り値
エラーが発生しなければ、 arg の誤差関数の値、すなわち {{mathjax-or|\(\frac{2}{\sqrt{\pi} }\int_{0}^{arg}{e^{-{t^2} }\mathsf{d}t}\)|
| 2 |
| √π |
∫arg
0e-t2
dt}} が返されます。
アンダーフローによる値域エラーが発生した場合、 (丸めた後の) 正しい結果、すなわち
| 2*arg |
| √π |
が返されます。
エラー処理
math_errhandling で規定されている通りにエラーが報告されます。
処理系が IEEE 浮動小数点算術 (IEC 60559) をサポートしている場合、
- 引数が ±0 であれば、 ±0 が返されます。
- 引数が ±∞ であれば、 ±1 が返されます。
- 引数が NaN であれば、 NaN が返されます。
ノート
|arg| < DBL_MIN*(sqrt(π)/2) の場合、アンダーフローが保証されます。
erf(
| x |
| σ√2 |
は、誤差が標準偏差 σ の正規分布である測定値の、平均値からの距離が x より小さい確率です。
例
Run this code
#include <stdio.h>
#include <math.h>
double phi(double x1, double x2)
{
return (erf(x2/sqrt(2)) - erf(x1/sqrt(2)))/2;
}
int main(void)
{
puts("normal variate probabilities:");
for(int n=-4; n<4; ++n)
printf("[%2d:%2d]: %5.2f%%\n", n, n+1, 100*phi(n, n+1));
puts("special values:");
printf("erf(-0) = %f\n", erf(-0.0));
printf("erf(Inf) = %f\n", erf(INFINITY));
}
出力:
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.000000
erf(Inf) = 1.000000
参考文献
- C11 standard (ISO/IEC 9899:2011):
- 7.12.8.1 The erf functions (p: 249)
- 7.25 Type-generic math <tgmath.h> (p: 373-375)
- F.10.5.1 The erf functions (p: 525)
- C99 standard (ISO/IEC 9899:1999):
- 7.12.8.1 The erf functions (p: 230)
- 7.22 Type-generic math <tgmath.h> (p: 335-337)
- F.9.5.1 The erf functions (p: 462)
関連項目
(C99)(C99)(C99) |
相補誤差関数を計算します (関数) |
erf の C++リファレンス
| |
外部リンク
Weisstein, Eric W. "Erf." From MathWorld--A Wolfram Web Resource.