Quantcast
Viewing latest article 6
Browse Latest Browse All 485

Answer by Federico klez Culloca for Why does misusing 1 instead of 1.0 from an int exceeding limits effect the value we get when we convert it to a double

In the first case a + a overflows to Integer.MIN_VALUE, then you switch to a double context with -1.0 which gives a negative number (Integer.MIN_VALUE - 1), since a double can hold a number smaller than Integer.MIN_VALUE.

In the second example you stay in an int context, which means that a + a overflows to Integer.MIN_VALUE, then subtracting 1 from that underflows and takes you back to Integer.MAX_VALUE.


Viewing latest article 6
Browse Latest Browse All 485

Trending Articles