I specifically print out the result :
System.out.println("f/c = " + f/c); //f/c = Infinity , where f is double
but this will get ArithmeticException :
System.out.println("d/c = " + d/c); // ArithmeticException : / by zero , where d is long
Why there is a difference? Why both of them throw ArithmeticException?
Jen P
Level 26
Why there is no "Arithmetic Error" when calculating d = (a + f/c +b) where byte c is actually 0 ?
Resolved
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Nithin
22 July 2019, 08:45solution
The IEEE has defined certain standards for floating point numbers which include definitions for "Not a Number"(NaN) and positive and negative infinity. These do not apply to integers.
so, the jvm won't throw an exception when double/0 or long/0.0. But if it is an integer division it will throw an arithmetic exception
+8