erfc, erfcf, erfcl
From cppreference.net
Common mathematical functions
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<math.h>
|
||
|
float
erfcf
(
float
arg
)
;
|
(1) | (C99 起) |
|
double
erfc
(
double
arg
)
;
|
(2) | (C99 起) |
|
long
double
erfcl
(
long
double
arg
)
;
|
(3) | (C99 起) |
|
定义于头文件
<tgmath.h>
|
||
|
#define erfc( arg )
|
(4) | (C99 起) |
4)
类型泛型宏:若
arg
具有
long
double
类型,则调用
erfcl
。否则,若
arg
具有整数类型或
double
类型,则调用
erfc
。否则调用
erfcf
。
目录 |
参数
| arg | - | 浮点数值 |
返回值
If no errors occur, value of the complementary error function of arg , that is \(\frac{2}{\sqrt{\pi} }\int_{arg}^{\infty}{e^{-{t^2} }\mathsf{d}t}\)| 2 |
| √ π |
arg e -t 2
d t or \({\small 1-\operatorname{erf}(arg)}\) 1-erf(arg) , is returned.
如果由于下溢发生范围错误,将返回正确结果(舍入后)。
错误处理
错误报告方式遵循
math_errhandling
中的规范。
如果实现支持 IEEE 浮点算术 (IEC 60559),
- 若参数为 +∞,则返回 +0。
- 若参数为 -∞,则返回 2。
- 若参数为 NaN,则返回 NaN。
注释
对于 IEEE 兼容类型
double
,当
arg
>
26.55
时保证会发生下溢。
示例
运行此代码
#include <math.h> #include <stdio.h> double normalCDF(double x) // Phi(-∞, x) 即 N(x) { return erfc(-x / sqrt(2)) / 2; } int main(void) { puts("正态累积分布函数:"); for (double n = 0; n < 1; n += 0.1) printf("normalCDF(%.2f) %5.2f%%\n", n, 100 * normalCDF(n)); printf("特殊值:\n" "erfc(-Inf) = %f\n" "erfc(Inf) = %f\n", erfc(-INFINITY), erfc(INFINITY)); }
输出:
正态累积分布函数: normalCDF(0.00) 50.00% normalCDF(0.10) 53.98% normalCDF(0.20) 57.93% normalCDF(0.30) 61.79% normalCDF(0.40) 65.54% normalCDF(0.50) 69.15% normalCDF(0.60) 72.57% normalCDF(0.70) 75.80% normalCDF(0.80) 78.81% normalCDF(0.90) 81.59% normalCDF(1.00) 84.13% 特殊值: erfc(-Inf) = 2.000000 erfc(Inf) = 0.000000
参考文献
- C23 标准 (ISO/IEC 9899:2024):
-
- 7.12.8.2 erfc 函数 (p: 249-250)
-
- 7.25 类型泛型数学 <tgmath.h> (p: 373-375)
-
- F.10.5.2 erfc 函数 (p: 525)
- C17 标准 (ISO/IEC 9899:2018):
-
- 7.12.8.2 erfc 函数 (页码: 249-250)
-
- 7.25 泛型数学 <tgmath.h> (页码: 373-375)
-
- F.10.5.2 erfc 函数 (页码: 525)
- C11 标准 (ISO/IEC 9899:2011):
-
- 7.12.8.2 erfc 函数 (p: 249-250)
-
- 7.25 泛型数学 <tgmath.h> (p: 373-375)
-
- F.10.5.2 erfc 函数 (p: 525)
- C99标准(ISO/IEC 9899:1999):
-
- 7.12.8.2 erfc函数(页码:230)
-
- 7.22 泛型数学 <tgmath.h>(页码:335-337)
-
- F.9.5.2 erfc函数(页码:462)
参见
|
(C99)
(C99)
(C99)
|
计算误差函数
(函数) |
|
C++ 文档
关于
erfc
|
|
外部链接
| 魏斯坦, 埃里克·W. "补余误差函数." 摘自 MathWorld —— 一个 Wolfram 网络资源。 |