erf, erff, erfl
來自 cppreference.com
定義於標頭檔案 <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 的誤差函式值,即2 |
√π |
0e-t2
dt。如果由於下溢發生範圍錯誤,則返回正確結果(舍入後),即
2*arg |
√π |
[編輯] 錯誤處理
錯誤按 math_errhandling
中指定的方式報告。
如果實現支援 IEEE 浮點運算 (IEC 60559),
- 如果引數為 ±0,則返回 ±0
- 如果引數為 ±∞,則返回 ±1
- 如果引數為 NaN,則返回 NaN
[編輯] 注意
如果 |arg| < DBL_MIN*(sqrt(π)/2),則保證下溢。
erf(x |
σ√2 |
[編輯] 示例
執行此程式碼
#include <math.h> #include <stdio.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 標準 (ISO/IEC 9899:2011)
- 7.12.8.1 erf 函式 (p: 249)
- 7.25 型別通用數學 <tgmath.h> (p: 373-375)
- F.10.5.1 erf 函式 (p: 525)
- C99 標準 (ISO/IEC 9899:1999)
- 7.12.8.1 erf 函式 (p: 230)
- 7.22 型別通用數學 <tgmath.h> (p: 335-337)
- F.9.5.1 erf 函式 (p: 462)
[編輯] 參閱
(C99)(C99)(C99) |
計算補餘誤差函式 (函式) |
C++ 文件 用於 erf
|
[編輯] 外部連結
Weisstein, Eric W. "Erf." 來自 MathWorld — Wolfram 網路資源。 |