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?
Why there is no "Arithmetic Error" when calculating d = (a + f/c +b) where byte c is actually 0 ?
You must be signed in to leave a comment
22 July 2019, 08:45
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