Namespaces
Variants

std:: feclearexcept

From cppreference.net
Floating-point environment
Functions
feclearexcept
(C++11)
(C++11) (C++11)
(C++11) (C++11)
Macro constants
(C++11)
헤더 파일에 정의됨 <cfenv>
int feclearexcept ( int excepts ) ;
(C++11부터)

excepts 인수에 나열된 부동 소수점 예외를 지우려고 시도합니다. excepts 부동 소수점 예외 매크로 의 비트별 OR입니다.

목차

매개변수

excepts - 지울 예외 플래그들을 나열하는 비트마스크

반환값

0 표시된 모든 예외가 성공적으로 제거되었거나 excepts 가 0인 경우. 오류 발생 시 0이 아닌 값을 반환합니다.

예제

#include <cfenv>
#include <cmath>
#include <iostream>
// #pragma STDC FENV_ACCESS ON
volatile double zero = 0.0; // volatile not needed where FENV_ACCESS is supported
volatile double one = 1.0;  // volatile not needed where FENV_ACCESS is supported
int main()
{
    std::feclearexcept(FE_ALL_EXCEPT);
    std::cout <<  "1.0/0.0 = " << 1.0 / zero << '\n';
    if (std::fetestexcept(FE_DIVBYZERO))
        std::cout << "division by zero reported\n";
    else
        std::cout << "division by zero not reported\n";
    std::feclearexcept(FE_ALL_EXCEPT);
    std::cout << "1.0/10 = " << one / 10 << '\n';
    if (std::fetestexcept(FE_INEXACT))
        std::cout << "inexact result reported\n";
    else
        std::cout << "inexact result not reported\n";
    std::feclearexcept(FE_ALL_EXCEPT);
    std::cout << "sqrt(-1) = " << std::sqrt(-1) << '\n';
    if (std::fetestexcept(FE_INVALID))
        std::cout << "invalid result reported\n";
    else
        std::cout << "invalid result not reported\n";
}

가능한 출력:

1.0/0.0 = inf
division by zero reported
1.0/10 = 0.1
inexact result reported
sqrt(-1) = -nan
invalid result reported

참고 항목

지정된 부동 소수점 상태 플래그 중 설정된 것을 결정합니다
(함수)
C documentation for feclearexcept