名稱空間
變體
操作

std::erfc, std::erfcf, std::erfcl

來自 cppreference.com
< cpp‎ | 數值‎ | 數學
 
 
 
常用數學函式
函式
基本操作
(C++11)  
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
指數函式
(C++11)
(C++11)

(C++11)
(C++11)
冪函式
(C++11)
(C++11)
三角
雙曲函式
(C++11)
(C++11)
(C++11)

誤差函式和伽馬函式
(C++11)
erfc
(C++11)
(C++11)
(C++11)
取整浮點運算
(C++11)(C++11)(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
浮點操縱函式
(C++11)(C++11)
(C++11)
(C++11)
(C++11)(C++11)
(C++11)
分類和比較
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
型別
(C++11)
(C++11)
(C++11)
宏常量
分類
(C++11)(C++11)(C++11)(C++11)(C++11)


 
定義於標頭檔案 <cmath>
(1)
float       erfc ( float num );

double      erfc ( double num );

long double erfc ( long 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>

            erfc ( const V& v_num );
(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
(有關它們的定義,請參閱 math-floating-pointdeduced-simd-t。)
(C++26 起)
A) 為所有整數型別提供了額外的過載,它們被視為 double
(C++11 起)

目錄

[編輯] 引數

num - 浮點值或整數值

[編輯] 返回值

如果沒有發生錯誤,則返回 num 的補充誤差函式值,即
2
π

num
e-t2
dt
1-erf(num)

如果因下溢發生範圍錯誤,則返回正確結果(舍入後)。

[編輯] 錯誤處理

錯誤按 math_errhandling 指定的方式報告。

如果實現支援 IEEE 浮點運算 (IEC 60559),

  • 如果引數為 +∞,則返回 +0。
  • 如果引數為 -∞,則返回 2。
  • 如果引數為 NaN,則返回 NaN。

[編輯] 注意

對於 IEEE 相容型別 double,如果 num > 26.55 則保證下溢。

額外的過載不需要完全按照 (A) 提供。它們只需足以確保對於整數型別的引數 numstd::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。