| Java FAQ | ||
| JSP FAQ | ||
| Servlet FAQ | ||
XyzWs Java FAQ:
Does JVM throw Exceptions for Floating-point arithmetic operations?
Printer-friendly version |
Mail this to a friend
|
Advertisement
|
Does JVM throw Exceptions for Floating-point arithmetic operations?According to 3.8 Floating-Point Arithmetic. The JVM throws no Exception as a result of any floating-point operations. Special values, such as positive and negative infinity or NaN, are returned as the result of suspicious operations such as positive value, negative value and zero division by zero. For example,
class Program {
public static void main(String[] args) {
double d1 = 1.0;
double d2 = 0.0;
byte b =1;
d1 = d1/d2;
b = (byte)d1;
System.out.print(b);
}
}
The output is -1 and no exception throw. The process involved is:
From IEEE 754 standards: The values +infinity and -infinity are denoted with an exponent of all '1's and a fraction of all 0s. The sign bit distinguishes between negative infinity and positive infinity. Being able to denote infinity as a specific value is useful because it allows operations to continue past overflow situations. Floating-point value
|