I found a small question yesterday :
If you write down the code like this and run it:
System.out.println(1/0);
It will throw a Exception.
But if you write this:
System.out.println(1/0.0);
It will print 'Infinity' on your screen.
I want to know that ,why can 0.0 be a divisor? The answer I got online was
0.0 and 0 are not the same, 0.0 is a float, 0 is a int.
or
Computers use binary representations of numeric values, and some numbers cannot be accurately represented, such as 0.1, so 0.0 and 0 is not the same,When the value of a floating-point number is 0.0, the actual stored value is not the exact 0.0, but a value very close to zero.
My idea is that for the first statement, 0.0 and 0 are essentially the same when doing arithmetic, regardless of type, If 0 cannot be a divisor, 0.0 cannot be either. For the second statement, although the binary number can not accurately represent some numbers, but the binary can accurately represent 0.0 .
Why is it normal to use 0.0 as a divisor?