- cmath[meta header]
- std[meta namespace]
- function[meta id-type]
- cpp11[meta cpp]
- [mathjax enable]
namespace std {
float erf(float x);
double erf(double x);
long double erf(long double x);
double erf(Integral x);
float erff(float x); // C++17 から
long double erfl(long double x); // C++17 から
}- Integral[italic]
算術型の誤差関数 (error function) を求める。
引数 x の誤差関数を返す。
- $$ f(x) = \mathrm{erf}~x \equiv \frac{2}{\sqrt{\pi}} \int_0^x e^{-t^2} dt $$
- C++11 以降では、処理系が IEC 60559 に準拠している場合(
std::numeric_limits<T>::is_iec559() != false)、以下の規定が追加される。-
x = ±0の場合、戻り値は±0となる。 -
x = ±∞の場合、戻り値は±1となる。
-
- 平均μ, 標準偏差σの正規分布の累積分布関数は
$$\frac{1}{2} \left( 1 + \mathrm{erf} ~ \frac{x - \mu}{\sqrt{2} \sigma} \right)$$ で与えられる。
#include <cmath>
#include <iostream>
#include <limits>
int main() {
std::cout << std::fixed;
std::cout << "erf(-∞) = " << std::erf(-std::numeric_limits<double>::infinity()) << std::endl;
std::cout << "erf(0) = " << std::erf(0.0) << std::endl;
std::cout << "erf(1) = " << std::erf(1.0) << std::endl;
std::cout << "erf(+∞) = " << std::erf(std::numeric_limits<double>::infinity()) << std::endl;
}- std::erf[color ff0000]
- std::fixed[link ../ios/fixed.md]
- infinity()[link ../limits/numeric_limits/infinity.md]
erf(-∞) = -1.000000
erf(0) = 0.000000
erf(1) = 0.842701
erf(+∞) = 1.000000
- C++11
- Clang, C++11 mode: 3.0
- GCC, C++11 mode: 4.3.6
- ICC: ??
- Visual C++: ??
特定の環境で constexpr 指定されている場合がある。(独自拡張)
- GCC 4.6.1 以上