std::erfc
来自cppreference.com
定义于头文件 <cmath>
|
||
float erfc( float arg ); |
(1) | (C++11 起) |
double erfc( double arg ); |
(2) | (C++11 起) |
long double erfc( long double arg ); |
(3) | (C++11 起) |
double erfc( Integral arg ); |
(4) | (C++11 起) |
目录 |
[编辑] 参数
arg | - | 浮点或整数类型值 |
[编辑] 返回值
若不发生错误,则返回arg
的补误差函数的值,即 2 |
√π |
arge-t2
dt 或 1-erf(arg) 。
若发生源于下溢的值域错误,则返回(舍入后的)正确结果。
[编辑] 错误处理
报告 math_errhandling 中指定的错误。
若实现支持 IEEE 浮点算术( IEC 60559 ),则
- 若参数为 +∞ ,则返回 +0
- 若参数为 -∞ ,则返回 2
- 若参数为 NaN ,则返回 NaN
[编辑] 注意
对于 IEEE 兼容的 double
类型,若 arg
> 26.55 则保证下溢。
[编辑] 示例
运行此代码
#include <iostream> #include <cmath> #include <iomanip> double normalCDF(double x) // Phi(-∞, x) 又称为 N(x) { return std::erfc(-x/std::sqrt(2))/2; } int main() { std::cout << "normal cumulative distribution function:\n" << std::fixed << std::setprecision(2); for(double n=0; n<1; n+=0.1) std::cout << "normalCDF(" << n << ") " << 100*normalCDF(n) << "%\n"; std::cout << "special values:\n" << "erfc(-Inf) = " << std::erfc(-INFINITY) << '\n' << "erfc(Inf) = " << std::erfc(INFINITY) << '\n'; }
输出:
normal cumulative distribution function: 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% special values: erfc(-Inf) = 2.00 erfc(Inf) = 0.00
[编辑] 参阅
(C++11) |
误差函数 (函数) |
erfc 的 C 文档
|
[编辑] 外部链接
Weisstein, Eric W. "Erfc." 来自 MathWorld--A Wolfram Web Resource 。