std::erfc, std::erfcf, std::erfcl
來自 cppreference.com
定義於標頭檔案 <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) |
1-3) 計算 num 的補充誤差函式,即 1.0 - std::erf(num),但對於較大的 num 不會損失精度。 庫為所有 cv 非限定浮點型別提供了
std::erfc
的過載作為引數型別。(C++23 起)
S) SIMD 過載對 v_num 執行逐元素的
std::erfc 。
|
(C++26 起) |
A) 為所有整數型別提供了額外的過載,它們被視為 double。
|
(C++11 起) |
目錄 |
[編輯] 引數
num | - | 浮點值或整數值 |
[編輯] 返回值
如果沒有發生錯誤,則返回 num 的補充誤差函式值,即2 |
√π |
nume-t2
dt 或 1-erf(num)。
如果因下溢發生範圍錯誤,則返回正確結果(舍入後)。
[編輯] 錯誤處理
錯誤按 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) aka 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)(C++11)(C++11) |
誤差函式 (函式) |
C 文件 為 erfc
|
[編輯] 外部連結
Weisstein, Eric W. "Erfc." 來自 MathWorld — A Wolfram Web Resource。 |