Compliant libraries offer support for exception flags, according to the IEEE754 standard. For each exception, the implementation provides a status flag that is set when the exception occurs. The flag is cleared only at the user's request. The user can test and alter flags individually, or several at a time. Furthermore, all flags can be saved and restored.
There are five supported exceptions:
The five exception flags are defined in except.h: FP_EINVALID, FP_EDIVZERO, FP_EOVERFLOW, FP_EUNDERFLOW, FP_EINEXACT.
For example, in order to check if an operation has overflowed, the testFlags function is used:
if (testFlags(FP_EOVERFLOW)) { do_something(); }
Multiple flags can be checked at the same time:
if (testFlags(FP_EOVERFLOW | FP_EUNDERFLOW)) { do_something(); }
Flags that have been set by a certain floating point operation are not cleared by subsequent operations. The only way to clear flags is by using the lower_flags function:
lowerFlags(FP_INVALID | FP_EOVERFLOW | FP_EUNDERFLOW)
Finally, flags can be saved using the saveAllFlags() function. Any number and combination of flags can be restored to their previous state using the restoreFlags(char, char) function.