Floating point operations can detect several exceptional conditions and respond in several ways:
- Setting a status flag that can be subsequently tested.
- Create a trap right away.
The first mode of operation provides high performance, while the second mode allows you to immediately notify about potentially dangerous operations.
IEEE 754 defines some normal values for the result of operations that throw exceptions (for example: a final non-zero number and a divisor 0 → correctly signed INFINITY; 0/0 → Quiet NaN).
The goal of IEEE 754 with traps is that there will be user mode handlers that could check the operation, operands (to exclude Invalid Operation and Divide by Zero) or the result (to overflow, flaws and inaccurate exceptions) and exception flags and return a new user result.
In fact, some languages do not even support access to exception state flags, not to mention setting up hook traps.
Even C provides very primitive support for trap handlers; C99 does not even define a portable way to set the capture mode, requiring, for example, passing some value defined for implementation to fesetenv() . Implementations typically raise SIGFPE, and the user will typically need to access a processor dependent state to implement the IEEE-754 capture processor.
source share