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 (18171862)
“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 (18821941)