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 Jew is neither a newcomer nor an alien in this country or on this continent; his Americanism is as original and ancient as that of any race or people with the exception of the American Indian and other aborigines. He came in the caravels of Columbus, and he knocked at the gates of New Amsterdam only thirty-five years after the Pilgrim Fathers stepped ashore on Plymouth Rock.
    Oscar Solomon Straus (1850–1926)

    It is curious how instinctively one protects the image of oneself from idolatry or any other handling that could make it ridiculous, or too unlike the original to be believed any longer.
    Virginia Woolf (1882–1941)