ArithmeticException thrown in Java

floating-point, java, math

Solution

Because IEEE-754 floating point numbers have a representation for infinity, whereas integers don't.

In other words, every bit pattern in `int` represents a normal integer; floating point values are rather more complicated with +/- infinity, "not a number" (NaN) values, normalized values, subnormal values etc.

Problem

In Java, (Number/0) throws an ArithmeticException while (Number/0.0) = Infinity. Why does this happen?

Original source