C <fenv.h> - fexcept_t Type
The C <fenv.h> fenv_t type representing all floating-point status flags collectively, including the active floating-point exceptions along with any additional information the implementation associates with the flags. Its value will be set by calling fegetexceptflag(), and can be applied by calling fesetexceptflag().
Example:
The example below shows the usage of fexcept_t type.
#include <stdio.h> #include <fenv.h> #include <math.h> #pragma STDC FENV_ACCESS ON void FE_Exceptions_Message(void) { printf("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"); printf("\n"); } int main (){ //creating fexcept_t object fexcept_t excepts; //raising FE_DIVBYZERO exception feraiseexcept(FE_DIVBYZERO); FE_Exceptions_Message(); //storing current exception flag fegetexceptflag(&excepts,FE_ALL_EXCEPT); //clear previous exception flag and //create another exception flags feclearexcept(FE_ALL_EXCEPT); feraiseexcept(FE_INVALID | FE_INEXACT); FE_Exceptions_Message(); //restoring previous exception flags fesetexceptflag(&excepts,FE_ALL_EXCEPT); FE_Exceptions_Message(); return 0; }
The output of the above code will be:
Exceptions raised: FE_DIVBYZERO Exceptions raised: FE_INEXACT FE_INVALID Exceptions raised: FE_DIVBYZERO
❮ C <fenv.h> Library