3.6 No Exceptions! What happens when "bad" things occur during floating-point operations? The IEEE 754 standard specifies standard responses to five kinds of exceptions, as shown in Table 3-3. Java provides the standard responses. The result of an overflow is either - Infinity or + Infinity, and the result of an underflow is either a denormalized number, -0.0, or +0.0. The IEEE 754 standard also specifies that, when an exception occurs, the computer must signal it by setting an associated status flag, and this flag must stay set until the program clears it. The standard also specifies that a program be able to trap the exception or ignore it by masking it. Table 3-3. Standard responses to floating-point exceptions, as specified by the IEEE 754 standard.
Java deviates from this standard. Java's floating-point operations never throw exceptions. They are nonstop. Programs must check for the exceptions indirectly, such as by testing for NaN using the Float.isNaN() and Double.isNaN() methods , and we must be especially wary when results become - Infinity or + Infinity. |
Top |