Namespaces
Variants

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

From cppreference.net
Common mathematical functions
Nearest integer floating point operations
(C++11)
(C++11)
(C++11) (C++11) (C++11)
Floating point manipulation functions
(C++11) (C++11)
(C++11)
(C++11)
Classification and comparison
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Types
(C++11)
(C++11)
(C++11)
Macro constants
ヘッダー <cmath> で定義
(1)
float erfc ( float num ) ;

double erfc ( double num ) ;

long double erfc ( long double num ) ;
(C++23以前)
/*floating-point-type*/
erfc ( /*floating-point-type*/ num ) ;
(C++23以降)
(constexpr C++26以降)
float erfcf ( float num ) ;
(2) (C++11以降)
(constexpr C++26以降)
long double erfcl ( long double num ) ;
(3) (C++11以降)
(constexpr C++26以降)
ヘッダー <simd> で定義
template < /*math-floating-point*/ V >

constexpr /*deduced-simd-t*/ < V >

erfc ( const V & v_num ) ;
(S) (C++26以降)
ヘッダー <cmath> で定義
template < class Integer >
double erfc ( Integer num ) ;
(A) (constexpr C++26以降)
1-3) num 相補誤差関数 を計算する。これは 1.0 - std:: erf ( num ) であるが、大きな num に対して精度の低下がない。 ライブラリは、パラメータの型としてすべてのcv修飾されない浮動小数点型について std::erfc のオーバーロードを提供する。 (C++23以降)
S) SIMDオーバーロードは v_num に対して要素ごとに std::erfc を実行します。
(定義については math-floating-point および deduced-simd-t を参照)
(C++26以降)
A) すべての整数型に対して追加のオーバーロードが提供されており、これらは double として扱われます。
(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) aka 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

外部リンク

Weisstein, Eric W. "Erfc." MathWorld — Wolfram Web リソースより。