29 ms·
> The INT_MIN value need not have an additive inverse because of a quirk in two's complement. For comparison, in Java, these 3 expressions each yield Integer.M
by MaxBarraclough 2y ago
> The INT_MIN value need not have an additive inverse because of a quirk in two's complement.
For comparison, in Java, these 3 expressions each yield Integer.MIN_VALUE (i.e. -2147483648):
-Integer.MIN_VALUE
Integer.MIN_VALUE * -1
Integer.MIN_VALUE / -1
I have to admit I expected all 3 to throw.
edit On reflection I shouldn't have expected that, I recall reading John Regehr's blog post on the downsides of how Java defaults to wrapping behaviour: https://blog.regehr.org/archives/1401 https://blog.regehr.org/archives/1401