C <fenv.h> - FE_ALL_EXCEPT
The FE_ALL_EXCEPT macro expands to the bitwise OR of all possible floating-point exceptions defined in <fenv.h>. If no floating-point exceptions are supported by the implementation, this macro is defined as 0 (zero).
It can be used with functions that expect a bitmask of possible floating point exceptions as one of its arguments: feclearexcept(), fegetexceptflag(), feraiseexcept(), fesetexceptflag(), or fetestexcept().
Definition in the <fenv.h> header file is:
#define FE_ALL_EXCEPT FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW
The details about all floating-point exception macros are listed below:
Macros | Description |
---|---|
FE_DIVBYZERO | Pole error exception occurred in an earlier floating-point operation. |
FE_INEXACT | Inexact result exception occurred in an earlier floating-point operation (rounding was necessary to store the result). |
FE_INVALID | Invalid argument exception occurred (domain error occurred) in an earlier floating-point operation. |
FE_OVERFLOW | Overflow range error exception occurred in an earlier floating-point operation (result was too large to be representable). |
FE_UNDERFLOW | Underflow range error exception occurred in an earlier floating-point operation (result was subnormal with a loss of precision). |
FE_ALL_EXCEPT | Bitwise OR of all supported floating-point exceptions. |
Certain library implementations may define additional macro constants in <fenv.h> to identify additional floating-point exceptions (with their corresponding macros also beginning with FE_).
See math_errhandling for more details.
Example:
The example below shows the usage of FE_ALL_EXCEPT macro.
#include <stdio.h> #include <fenv.h> #include <float.h> #include <math.h> #pragma STDC FENV_ACCESS ON //volatile not needed if FENV_ACCESS is supported volatile double zero = 0.0; volatile double three = 3.0; 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"); feclearexcept(FE_ALL_EXCEPT); printf("\n"); } int main (){ printf("1/0.0 = %f\n", (1/zero)); FE_Exceptions_Message(); printf("1.0/3.0 = %f\n", (1.0/three)); FE_Exceptions_Message(); printf("sqrt(-1.0) = %f\n", sqrt(-1)); FE_Exceptions_Message(); printf("DBL_MAX*2 = %f\n", (DBL_MAX*2)); FE_Exceptions_Message(); printf("nextafter(DBL_MIN/pow(2.0,52),0.0) = %f\n", nextafter(DBL_MIN/pow(2.0,52),0.0)); FE_Exceptions_Message(); return 0; }
The output of the above code will be:
1/0.0 = inf Exceptions raised: FE_DIVBYZERO 1.0/3.0 = 0.333333 Exceptions raised: FE_INEXACT sqrt(-1.0) = -nan Exceptions raised: FE_INVALID DBL_MAX*2 = inf Exceptions raised: FE_INEXACT FE_OVERFLOW nextafter(DBL_MIN/pow(2.0,52),0.0) = 0.000000 Exceptions raised: FE_INEXACT FE_UNDERFLOW
❮ C <fenv.h> Library