Namespaces
Variants

std:: erf, std:: erff, std:: erfl

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 erf ( float num ) ;

double erf ( double num ) ;

long double erf ( long double num ) ;
(C++23まで)
/*floating-point-type*/
erf ( /*floating-point-type*/ num ) ;
(C++23から)
(constexpr C++26から)
float erff ( float num ) ;
(2) (C++11から)
(constexpr C++26から)
long double erfl ( long double num ) ;
(3) (C++11から)
(constexpr C++26から)
ヘッダーで定義 <simd>
template < /*math-floating-point*/ V >

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

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

目次

翻訳の説明: - 「Contents」を「目次」に翻訳しました - その他のテキスト(Parameters、Return value、Error handling、Notes、Example、See also、External links)はC++関連の専門用語として翻訳せず、原文のまま保持しました - HTMLタグ、属性、クラス名、IDなどはすべて変更せず保持しました - 番号やリンクなどの書式も完全に維持しました

パラメータ

num - 浮動小数点または整数値

戻り値

If no errors occur, value of the error function of num , that is
2
π
num
0
e -t 2
d t
, is returned.
If a range error occurs due to underflow, the correct result (after rounding), that is
2*num
π
is returned.

エラーハンドリング

エラーは、 math_errhandling で指定された通りに報告されます。

IEEE浮動小数点演算(IEC 60559)を実装がサポートしている場合、

  • 引数が±0の場合、±0が返されます。
  • 引数が±∞の場合、±1が返されます。
  • 引数がNaNの場合、NaNが返されます。

注記

アンダーフローは、以下の条件が満たされる場合に保証されます: | num | < DBL_MIN * ( std:: sqrt ( π ) / 2 )

erf(
x
σ 2
)
is the probability that a measurement whose errors are subject to a normal distribution with standard deviation σ is less than x away from the mean value.

追加のオーバーロードは (A) と完全に同一である必要はありません。整数型の引数 num に対して、 std :: erf ( num ) std :: erf ( static_cast < double > ( num ) ) と同じ効果を持つことを保証するのに十分なものであればよいのです。

以下の例は、正規確率変数が区間 (x1, x2) に存在する確率を計算します:

#include <cmath>
#include <iomanip>
#include <iostream>
double phi(double x1, double x2)
{
    return (std::erf(x2 / std::sqrt(2)) - std::erf(x1 / std::sqrt(2))) / 2;
}
int main()
{
    std::cout << "Normal variate probabilities:\n"
              << std::fixed << std::setprecision(2);
    for (int n = -4; n < 4; ++n)
        std::cout << '[' << std::setw(2) << n
                  << ':' << std::setw(2) << n + 1 << "]: "
                  << std::setw(5) << 100 * phi(n, n + 1) << "%\n";
    std::cout << "Special values:\n"
              << "erf(-0) = " << std::erf(-0.0) << '\n'
              << "erf(Inf) = " << std::erf(INFINITY) << '\n';
}

出力:

Normal variate probabilities:
[-4:-3]:  0.13%
[-3:-2]:  2.14%
[-2:-1]: 13.59%
[-1: 0]: 34.13%
[ 0: 1]: 34.13%
[ 1: 2]: 13.59%
[ 2: 3]:  2.14%
[ 3: 4]:  0.13%
Special values:
erf(-0) = -0.00
erf(Inf) = 1.00

関連項目

(C++11) (C++11) (C++11)
相補誤差関数
(関数)
Cドキュメント を参照 erf

外部リンク

Weisstein, Eric W. "Erf." From MathWorld — A Wolfram Web Resource.
Weisstein, Eric W. "Erf." MathWorld — Wolfram Web リソースより。