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:

    The ways by which you may get money almost without exception lead downward. To have done anything by which you earned money merely is to have been truly idle or worse.
    Henry David Thoreau (1817–1862)

    Madam, a circulating library in a town is as an evergreen tree of diabolical knowledge; it blossoms through the year. And depend on it ... that they who are so fond of handling the leaves, will long for the fruit at last.
    Richard Brinsley Sheridan (1751–1816)