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
Definiert im Header <cmath>
(1)
float erf ( float num ) ;

double erf ( double num ) ;

long double erf ( long double num ) ;
(bis C++23)
/*floating-point-type*/
erf ( /*floating-point-type*/ num ) ;
(seit C++23)
(constexpr seit C++26)
float erff ( float num ) ;
(2) (seit C++11)
(constexpr seit C++26)
long double erfl ( long double num ) ;
(3) (seit C++11)
(constexpr seit C++26)
SIMD-Überladung (seit C++26)
Definiert im Header <simd>
template < /*math-floating-point*/ V >

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

erf ( const V & v_num ) ;
(S) (seit C++26)
Definiert im Header <cmath>
template < class Integer >
double erf ( Integer num ) ;
(A) (constexpr seit C++26)
1-3) Berechnet die Fehlerfunktion von num . Die Bibliothek bietet Überladungen von std::erf für alle cv-unqualifizierten Gleitkommatypen als Typ des Parameters an. (since C++23)
S) Die SIMD-Überladung führt eine elementweise std::erf auf v_num aus.
(Siehe math-floating-point und deduced-simd-t für deren Definitionen.)
(seit C++26)
A) Zusätzliche Überladungen werden für alle Ganzzahltypen bereitgestellt, die als double behandelt werden.
(since C++11)

Inhaltsverzeichnis

Parameter

num - Gleitkomma- oder Ganzzahlwert

Rückgabewert

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.

Fehlerbehandlung

Fehler werden gemeldet, wie in math_errhandling spezifiziert.

Wenn die Implementierung IEEE-Gleitkommaarithmetik (IEC 60559) unterstützt,

  • Wenn das Argument ±0 ist, wird ±0 zurückgegeben.
  • Wenn das Argument ±∞ ist, wird ±1 zurückgegeben.
  • Wenn das Argument NaN ist, wird NaN zurückgegeben.

Hinweise

Unterlauf ist garantiert, wenn | 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.

Die zusätzlichen Überladungen müssen nicht exakt wie (A) bereitgestellt werden. Sie müssen lediglich sicherstellen, dass für ihr Argument num vom Ganzzahltyp std :: erf ( num ) die gleiche Wirkung hat wie std :: erf ( static_cast < double > ( num ) ) .

Beispiel

Das folgende Beispiel berechnet die Wahrscheinlichkeit, dass eine normalverteilte Zufallsvariable im Intervall (x1, x2) liegt:

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

Ausgabe:

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

Siehe auch

(C++11) (C++11) (C++11)
Komplementäre Fehlerfunktion
(Funktion)

Externe Links

Weisstein, Eric W. "Erf." Von MathWorld — Eine Wolfram Web Resource.