Exception flags are set as side-effects of floating-point arithmetic operations and math library routines, and they remain set until explicitly cleared. The following macros expand to bit flags of type
int representing the five standard floating-point exceptions.
FE_DIVBYZERO
A divide-by-zero exception occurs when the program attempts to divide a finite non-zero number by zero.
FE_INEXACT
An inexact exception is raised whenever there is a loss of precision due to rounding.
FE_INVALID
Invalid operation exceptions occur when a program attempts to perform calculations for which there is no reasonable representable answer. For instance, subtraction of infinities, division of zero by zero, ordered comparison involving NaNs, and taking the square root of a negative number are all invalid operations.
FE_OVERFLOW
An overflow exception occurs when the magnitude of the result of a computation is too large to fit in the destination type.
FE_UNDERFLOW
Underflow occurs when the result of a computation is too close to zero to be represented as a non-zero value in the destination type.
Additionally, the
FE_ALL_EXCEPT macro expands to the bitwise OR of the above flags and any architecture-specific flags. Combinations of these flags are passed to the
feclearexcept(),
fegetexceptflag(),
feraiseexcept(),
fesetexceptflag(), and
fetestexcept() functions to clear, save, raise, restore, and examine the processor's floating-point exception flags, respectively.
Exceptions may be
unmasked with
feenableexcept() and masked with
fedisableexcept(). Unmasked exceptions cause a trap when they are produced, and all exceptions are masked by default. The current mask can be tested with
fegetexcept().