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

Header: <cmath>

1-3) Computes the error function of num.The library provides overloads of std::erf for all cv-unqualified floating-point types as the type of the parameter.(since C++23)

# Declarations

float erf ( float num );
double erf ( double num );
long double erf ( long double num );

(until C++23)

/*floating-point-type*/
erf ( /*floating-point-type*/ num );

(since C++23) (constexpr since C++26)

float erff( float num );

(since C++11) (constexpr since C++26)

long double erfl( long double num );

(since C++11) (constexpr since C++26)

SIMD overload (since C++26)
template< /*math-floating-point*/ V >
constexpr /*deduced-simd-t*/<V>
erf ( const V& v_num );

(since C++26)

Additional overloads (since C++11)
template< class Integer >
double erf ( Integer num );

(constexpr since C++26)

# Parameters

# Notes

Underflow is guaranteed if |num| < DBL_MIN * (std::sqrt(π) / 2).

The additional overloads are not required to be provided exactly as (A). They only need to be sufficient to ensure that for their argument num of integer type, std::erf(num) has the same effect as std::erf(static_cast(num)).

# Example

#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';
}

# See also