Exceptions

Typically, when a computation falls outside the realm of operations on real numbers, a numerical exception arises. CommonPoint platforms, following the IEEE arithmetic standards, group the various transgressions into five distinct exceptions:

  1. Invalid--the operation has no universally applicable mathematical definition. Examples are and . The result is a NaN.
  2. Overflow--the mathematical result is too large for the destination format. The computed result is or the largest finite number, with the sign of the mathematical result. Inexact is also raised.
  3. Underflow--the mathematical result is too small for the destination format. It is subnormalized and then rounded. The computed result has one of these values, with suitable algebraic sign, depending on the extent of subnormalization and the direction of rounding:
    • The smallest normal number
    • A subnormal number
    • Zero
    Underflow arises only when the subnormalized value is inexact (in which case inexact is also raised).
  4. Divide-by-zero--the computation touches a singularity such as or . The result is with appropriate sign.
  5. Inexact--the result is modified, however slightly, in order to fit the destination format.

Flags

In the CommonPoint system, raising a floating-point exception means raising the IEEE exception flag associated with it. Chapter 10 discusses access to the flags. A technique portable across many other platforms is to test for exceptions by polling the flags. The flags are clear when your application launches; they are set when the associated exception arises. Each flag is sticky in the sense that it remains set until you clear it. A typical use of flags is this:

  1. Clear the flag of interest.
  2. Perform a calculation.
  3. Test the flag, and proceed accordingly.
To use a flag in a more global scope, you can save the state of the flag before clearing it and then either restore it or restore a modified value, depending on the calculation. This is the technique used in the implementation of library functions like Sin and Tan, in which an underflow that might arise in the evaluation of a polynomial or rational approximation is hidden from the calling code unless it is deserved because the result is tiny and inexact.

C++ exceptions

See Chapter 10 for a discussion of the connection between IEEE exception flags and C++ exception objects.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker