?
This document uses PHP Chinese website manual Release
在頭文件<fenv.h>中定義 | ||
---|---|---|
int fetestexcept(int excepts); | (自C99以來) |
確定當(dāng)前設(shè)置了哪些浮點(diǎn)異常的指定子集。 參數(shù)excepts是浮點(diǎn)異常宏的按位或。
excepts | - | bitmask listing the exception flags to test |
---|
按位或運(yùn)算的異常宏都包含在excepts中,并與當(dāng)前設(shè)置的浮點(diǎn)異常相對應(yīng)。
#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: none1.0/0.0 = inf1.0/10.0 = 0.100000sqrt(-1) = -nan DBL_MAX*2.0 = infnextafter(DBL_MIN/pow(2.0,52),0.0) = 0.0current exceptions raised: FE_DIVBYZERO FE_INEXACT FE_INVALID FE_OVERFLOW FE_UNDERFLOW
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.6.2.5 fetestexcept函數(shù)(p:211-212)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.6.2.5 fetestexcept函數(shù)(p:192-193)
feclearexcept(C99) | 清除指定的浮點(diǎn)狀態(tài)標(biāo)志(函數(shù)) |
---|
| 用于fetestexcept 的C ++文檔 |