When an application performs a floating-point operation that
causes an exception condition or a library error, and the application
is not coded to detect and deal with the exception or error, the
default exception-handling response of the system may introduce
a dramatic amount of error into the continuing computation. The
types of exception conditions and errors that can have this effect
are
Invalid operation conditions
Division by zero conditions
Library domain and range errors (EDOM
and ERANGE)
“Exception Conditions” describes
the exception conditions.
Math
library routines generate domain errors when
they encounter invalid arguments; they generate range
errors when they overflow or when they generate exact
infinities from finite arguments.
Table 3-1 “Effects of Floating-Point
Exceptions and Library Errors” shows the effects
of these exceptions and errors on typical applications. In many
cases, the effect of an exception or a library error on a program
is catastrophic: that is, the program continues, but the results
it produces are meaningless. A common exception to this rule is
an underflow condition. An underflow means that the value returned
by the operation is extremely small. In many cases—for
example, if the program is evaluating a function at the point where
the function crosses the X axis—a value that is very near
zero is exactly what you want, so that the occurrence of an underflow
is actually a successful result. In other cases an overflow may
be an expected result. If, in the expression 1 + 1/f(x),
f(x) overflows,
then 1/f(x) is
0, and the expression evaluates to 1, which may be a perfectly acceptable
result.
Table 3-1 Effects of Floating-Point
Exceptions and Library Errors
Type of Error | Default System Behavior | Effect
on Application |
|---|
Overflow (ERANGE) | Substitute an infinity as the result | May
be catastrophic unless specifically handled |
Underflow | Substitute either a denormalized or zero
value as the result: if the result after rounding would be smaller
in magnitude than MINDOUBLE
(the smallest denormalized value), substitute zero | Application
usually continues successfully; however, performance may suffer
on some systems |
Invalid operation (invalid argument) (EDOM) | Substitute a NaN as the result | Probably
catastrophic unless specifically handled |
Division
by zero | Substitute
an infinity as the result | May be
catastrophic unless specifically handled |
The actual nature of the inaccuracies introduced by exceptions
and library errors depends on two main factors:
The programming environment selected
(C, Fortran)
The additional error-response behavior defined by
the programmer