std:: erfc, std:: erfcf, std:: erfcl
|
定义于头文件
<cmath>
|
||
| (1) | ||
|
float
erfc
(
float
num
)
;
double
erfc
(
double
num
)
;
|
(C++23 前) | |
|
/*浮点类型*/
erfc ( /*浮点类型*/ num ) ; |
(C++23 起)
(C++26 起为 constexpr) |
|
|
float
erfcf
(
float
num
)
;
|
(2) |
(C++11 起)
(C++26 起为 constexpr) |
|
long
double
erfcl
(
long
double
num
)
;
|
(3) |
(C++11 起)
(C++26 起为 constexpr) |
|
SIMD 重载
(C++26 起)
|
||
|
定义于头文件
<simd>
|
||
|
template
<
/*数学浮点类型*/
V
>
constexpr
/*推导出的 SIMD 类型*/
<
V
>
|
(S) | (C++26 起) |
|
附加重载
(C++11 起)
|
||
|
定义于头文件
<cmath>
|
||
|
template
<
class
Integer
>
double erfc ( Integer num ) ; |
(A) | (C++26 起为 constexpr) |
std::erfc
的重载版本作为参数类型。
(C++23 起)
|
S)
SIMD 重载对
v_num
执行逐元素的
std::erfc
运算。
|
(since C++26) |
|
A)
为所有整数类型提供了额外的重载,这些类型被视为
double
。
|
(since C++11) |
目录 |
参数
| num | - | 浮点数或整数值 |
返回值
If no errors occur, value of the complementary error function of num , that is| 2 |
| √ π |
num e -t 2
d t or 1-erf(num) , is returned.
如果由于下溢发生范围错误,将返回正确结果(舍入后)。
错误处理
错误报告方式遵循 math_errhandling 中的规范。
如果实现支持 IEEE 浮点算术 (IEC 60559),
- 若参数为 +∞,则返回 +0。
- 若参数为 -∞,则返回 2。
- 若参数为 NaN,则返回 NaN。
注释
对于IEEE兼容类型 double ,当 num > 26.55 时保证会发生下溢。
额外的重载并不要求必须完全按照 (A) 的形式提供。它们只需确保对于整数类型的实参 num , std :: erfc ( num ) 具有与 std :: erfc ( static_cast < double > ( num ) ) 相同的效果。
示例
#include <cmath> #include <iomanip> #include <iostream> double normalCDF(double x) // Phi(-∞, x) 即 N(x) { return std::erfc(-x / std::sqrt(2)) / 2; } int main() { std::cout << "正态累积分布函数:\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 << "特殊值:\n" << "erfc(-Inf) = " << std::erfc(-INFINITY) << '\n' << "erfc(Inf) = " << std::erfc(INFINITY) << '\n'; }
输出:
正态累积分布函数: 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.00 erfc(Inf) = 0.00
参见
|
(C++11)
(C++11)
(C++11)
|
误差函数
(函数) |
|
C 文档
关于
erfc
|
|
外部链接
| 魏斯坦, 埃里克·W. "补余误差函数." 摘自 MathWorld —— 一个 Wolfram 网络资源。 |