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
.