Namespaces
Variants

std:: fetestexcept

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

지정된 부동 소수점 예외 하위 집합 중 현재 설정된 예외를 결정합니다. 인수 excepts 부동 소수점 예외 매크로 들의 비트 OR 연산 결과입니다.

목차

매개변수

excepts - 테스트할 예외 플래그를 나열하는 비트마스크

반환값

excepts 에 포함되면서 현재 설정된 부동 소수점 예외에 해당하는 부동 소수점 예외 매크로들의 비트 OR 연산 결과입니다.

예제

#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 fetestexcept