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
Definido en el encabezado <cmath>
(1)
float erf ( float num ) ;

double erf ( double num ) ;

long double erf ( long double num ) ;
(hasta C++23)
/*floating-point-type*/
erf ( /*floating-point-type*/ num ) ;
(desde C++23)
(constexpr desde C++26)
float erff ( float num ) ;
(2) (desde C++11)
(constexpr desde C++26)
long double erfl ( long double num ) ;
(3) (desde C++11)
(constexpr desde C++26)
Sobrecarga SIMD (desde C++26)
Definido en el encabezado <simd>
template < /*math-floating-point*/ V >

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

erf ( const V & v_num ) ;
(S) (desde C++26)
Definido en el encabezado <cmath>
template < class Integer >
double erf ( Integer num ) ;
(A) (constexpr desde C++26)
1-3) Calcula la función de error de num . La biblioteca proporciona sobrecargas de std::erf para todos los tipos de punto flotante sin calificación cv como tipo del parámetro. (desde C++23)
S) La sobrecarga SIMD realiza un std::erf elemento por elemento en v_num .
(Ver math-floating-point y deduced-simd-t para sus definiciones.)
(desde C++26)
A) Se proporcionan sobrecargas adicionales para todos los tipos enteros, los cuales son tratados como double .
(since C++11)

Contenidos

Parámetros

num - valor de punto flotante o entero

Valor de retorno

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.

Manejo de errores

Los errores se reportan como se especifica en math_errhandling .

Si la implementación soporta aritmética de punto flotante IEEE (IEC 60559),

  • Si el argumento es ±0, se devuelve ±0.
  • Si el argumento es ±∞, se devuelve ±1.
  • Si el argumento es NaN, se devuelve NaN.

Notas

El subdesbordamiento está garantizado si | 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.

Las sobrecargas adicionales no requieren ser proporcionadas exactamente como (A) . Solo necesitan ser suficientes para garantizar que para su argumento num de tipo entero, std :: erf ( num ) tenga el mismo efecto que std :: erf ( static_cast < double > ( num ) ) .

Ejemplo

El siguiente ejemplo calcula la probabilidad de que una variable normal esté en el intervalo (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';
}

Salida:

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

Véase también

(C++11) (C++11) (C++11)
función de error complementaria
(función)

Enlaces externos

Weisstein, Eric W. "Erf." De MathWorld — Un recurso web de Wolfram.