erf
在头文件中定义
float erff(float arg);
(1)
(自C99以来)
double erf(double arg);
(2)
(自C99以来)
long double erfl(long double arg);
(3)
(自C99以来)
在头文件中定义
#define erf(arg)
(4)
(自C99以来)
1-3)计算arg的误差函数。
4)类型 - 通用宏:如果arg的类型是long double,则调用erfl。 否则,如果arg具有整数类型或类型double,则调用erf。 否则,erff被调用。
参数
arg
-
floating point value
返回值
如果没有错误发生,arg的错误函数的值为:
| 2 |
|:----|
| √π |
∫arg
0e-t2
d t被返回。如果由于下溢而发生范围错误,则正确的结果(四舍五入后)为:
| 2*arg |
|:----|
| √π |
,返回。
错误处理
按照math_errhandling中的指定报告错误。
如果实现支持IEEE浮点运算(IEC 60559),
如果参数为±0,则返回±0
如果参数为±∞,则返回±1
如果参数是NaN,则返回NaN
注意
如果| arg |,则保证下溢
| x |
|:----|
| σ√2 |
)是误差符合标准偏差σ的正态分布的测量值小于平均值的x的概率。
例
#include
#include
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) = %fn", erf(-0.0));
printf("erf(Inf) = %fn", 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类型通用数学(p:373-375)
F.10.5.1 erf函数(p:525)
C99标准(ISO / IEC 9899:1999): 7.12.8.1 erf函数(p:230)
7.22类型通用数学(p:335-337)
F.9.5.1 erf函数(p:462)
扩展内容
erfcerfcferfcl (C99)(C99)(C99)
计算互补误差函数(函数)
| erf 的C ++文档|