I noticed something weird earlier today. I was writing some code that was supposed to make graphs in complex quadrants. Anyway, I typed int i = 1/0; and it wouldn't compile. When I changed the code to double i = 1.0/0.0; the code compiled fine. When I ran the code it gave an error / by 0. I was expecting that... But why does it compile fine when using doubles and not integers? I am using the Blue J IDE
Dividing an int value by zero would result in a ArithmeticException, hence the expression 1 / 0 is illegal.
The result of dividing a double value by zero is infinity or NaN *, so the expression 1.0 / 0.0 is legal.
*) See t_over's comment for specifics:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With