Next: Systems Aspects, from D.
Up: Computer Representation of Numbers
Previous: Summary
  Contents
Each exception is signaled by setting an associate status flag;
the flag remains set until explicitly cleared. The user is able to read
and write the status flags. There are 5 status flags (one for each possible
exception type); in addition, for each flag there is a trap enable
bit (see below), and there are 4 rounding modes bits.
If the result of a computation is, say, ,
the flag values help user decide whether
this is the effect of an overflow or is a genuine infinity, like .
The programmer has the option to
- Mask the exception.
The appropriate flag is set and the program continues
with the standard response shown in the
table;
- Trap the exception. Occurrence of the exception
triggers a call to a special routine, the trap handler.
Trap handlers
- receive the values of the operands which lead to the exception,
or the result;
- clear or set the status flag; and
- return a value
that will be used as the result of the faulty operation.
Using trap handler calls for each inexact operation is prohibitive.
For overflow/underflow, the argument to the trap handler is the result,
with a modified exponent (the "wrapped-around" result). In single precision
the exponent is decreased/increased by 192, and in double precision by 1536,
followed by a rounding of the number to the corresponding precision.
Trap handlers are useful for backward compatibility, when an old code
expects to be
aborted if exception occurs. Example (from D. Goldberg, page 189):
without aborting, the sequence
will loop indefinitely if x becomes NaN.
Next: Systems Aspects, from D.
Up: Computer Representation of Numbers
Previous: Summary
  Contents
Adrian Sandu
2001-08-26