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 이후)
(C++26 이후 constexpr)
float erff ( float num ) ;
(2) (C++11 이후)
(C++26 이후 constexpr)
long double erfl ( long double num ) ;
(3) (C++11 이후)
(C++26 이후 constexpr)
SIMD 오버로드 (C++26 이후)
헤더 파일에 정의됨 <simd>
template < /*math-floating-point*/ V >

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

erf ( const V & v_num ) ;
(S) (C++26 이후)
추가 오버로드 (C++11 이후)
헤더 파일에 정의됨 <cmath>
template < class Integer >
double erf ( Integer num ) ;
(A) (C++26 이후 constexpr)
1-3) num 오차 함수 를 계산합니다. 라이브러리는 매개변수 타입으로 모든 cv-unqualified 부동소수점 타입에 대한 std::erf 의 오버로드를 제공합니다. (C++23부터)
S) SIMD 오버로드는 v_num 에 대해 요소별(element-wise) std::erf 연산을 수행합니다.
(정의에 대해서는 math-floating-point deduced-simd-t 를 참조하십시오.)
(C++26부터)
A) 모든 정수 타입에 대해 추가 오버로드가 제공되며, 이들은 double 로 처리됩니다.
(since C++11)

목차

매개변수

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 문서 for erf

외부 링크

Weisstein, Eric W. "Erf." MathWorld — Wolfram 웹 리소스에서.