IEEE Floating Point - Exception Handling

Exception Handling

The standard defines five exceptions, each of which returns a default value and has a corresponding status flag that (except in certain cases of underflow) is raised when the exception occurs. No other exception handling is required, but additional non-default alternatives are recommended (see below).

The five possible exceptions are:

  • Invalid operation (e.g., square root of a negative number) (returns qNaN by default).
  • Division by zero (an operation on finite operands gives an exact infinite result, e.g., 1/0 or log(0)) (returns ±infinity by default).
  • Overflow (a result is too large to be represented correctly) (returns ±infinity by default (for round-to-nearest mode)).
  • Underflow (a result is very small (outside the normal range) and is inexact) (returns a denormalized value by default).
  • Inexact (returns correctly rounded result by default).

These are the same five exceptions as were defined in IEEE 754-1985, but the division by zero exception has been extended to operations other than the division.

For decimal floating point, there are additional exceptions along with the above:

  • Clamped (a result's exponent is too large for the destination format). By default, trailing zeros will be added to the coefficient to reduce the exponent to the largest usable value. If this is not possible (because this would cause the number of digits needed is more than the destination format) then overflow occurs.
  • Rounded (a result's coefficient requires more digits than the destination format provides). The inexact is signaled if any non-zero digits are discarded.

Additionally, operations like quantize when either operand is infinite, or when the result does not fit the destination format, will also signal invalid operation exception.

Read more about this topic:  IEEE Floating Point

Famous quotes containing the words exception and/or handling:

    For a parent, it’s hard to recognize the significance of your work when you’re immersed in the mundane details. Few of us, as we run the bath water or spread the peanut butter on the bread, proclaim proudly, “I’m making my contribution to the future of the planet.” But with the exception of global hunger, few jobs in the world of paychecks and promotions compare in significance to the job of parent.
    Joyce Maynard (20th century)

    Mothers risk alienating their mates if they expect them to hold or care for the baby exactly as they do. Fathers who are constantly criticized or corrected may lose interest in handling the baby, and this is a loss for everyone. The cycle is a dangerous one. Now the same mother feels bitter because she is no longer getting any help at home.
    Cathy Rindner Tempelsman (20th century)