next up previous contents
Next: Systems Aspects, from D. Up: Computer Representation of Numbers Previous: Summary   Contents

Flags and Exception Trapping

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

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 up previous contents
Next: Systems Aspects, from D. Up: Computer Representation of Numbers Previous: Summary   Contents
Adrian Sandu 2001-08-26