fetestexcept
From cppreference.net
|
헤더 파일에 정의됨
<fenv.h>
|
||
|
int
fetestexcept
(
int
excepts
)
;
|
(C99부터) | |
지정된 부동 소수점 예외 하위 집합 중 현재 설정된 예외를 결정합니다. 인수
excepts
는
부동 소수점 예외 매크로
들의 비트 OR입니다.
목차 |
매개변수
| excepts | - | 테스트할 예외 플래그를 나열하는 비트마스크 |
반환값
excepts
에 포함되면서 현재 설정된 부동 소수점 예외에 해당하는 부동 소수점 예외 매크로들의 비트 OR 연산 결과입니다.
예제
이 코드 실행
#include <stdio.h> #include <math.h> #include <fenv.h> #include <float.h> #pragma STDC FENV_ACCESS ON void show_fe_exceptions(void) { printf("current exceptions raised: "); if(fetestexcept(FE_DIVBYZERO)) printf(" FE_DIVBYZERO"); if(fetestexcept(FE_INEXACT)) printf(" FE_INEXACT"); if(fetestexcept(FE_INVALID)) printf(" FE_INVALID"); if(fetestexcept(FE_OVERFLOW)) printf(" FE_OVERFLOW"); if(fetestexcept(FE_UNDERFLOW)) printf(" FE_UNDERFLOW"); if(fetestexcept(FE_ALL_EXCEPT)==0) printf(" none"); printf("\n"); } int main(void) { /* Show default set of exception flags. */ show_fe_exceptions(); /* Perform some computations which raise exceptions. */ printf("1.0/0.0 = %f\n", 1.0/0.0); /* FE_DIVBYZERO */ printf("1.0/10.0 = %f\n", 1.0/10.0); /* FE_INEXACT */ printf("sqrt(-1) = %f\n", sqrt(-1)); /* FE_INVALID */ printf("DBL_MAX*2.0 = %f\n", DBL_MAX*2.0); /* FE_INEXACT FE_OVERFLOW */ printf("nextafter(DBL_MIN/pow(2.0,52),0.0) = %.1f\n", nextafter(DBL_MIN/pow(2.0,52),0.0)); /* FE_INEXACT FE_UNDERFLOW */ show_fe_exceptions(); return 0; }
출력:
current exceptions raised: none 1.0/0.0 = inf 1.0/10.0 = 0.100000 sqrt(-1) = -nan DBL_MAX*2.0 = inf nextafter(DBL_MIN/pow(2.0,52),0.0) = 0.0 current exceptions raised: FE_DIVBYZERO FE_INEXACT FE_INVALID FE_OVERFLOW FE_UNDERFLOW
참고문헌
- C11 표준 (ISO/IEC 9899:2011):
-
- 7.6.2.5 fetestexcept 함수 (p: 211-212)
- C99 표준 (ISO/IEC 9899:1999):
-
- 7.6.2.5 fetestexcept 함수 (p: 192-193)
참조 항목
|
(C99)
|
지정된 부동 소수점 상태 플래그를 지움
(함수) |
|
C++ 문서
for
fetestexcept
|
|