For 2's complement signed integers of 32 bits, intmin
is 0x80000000
, or indeed -2147483648
. However, intmax
is 0x7FFFFFFF
, which is only 2147483647
. This means that the negation of intmin
would be 2147483648
, which can't be represented in 32-bit signed integers.
MATLAB actually does something odd. Under the normal rules of 2's complement, 0 - 0x80000000
should give 0x80000000
again. However, according to MATLAB, 0 - 0x80000000 = 0x7FFFFFFF
. This should explain why abs(intmin) = intmax
holds for MATLAB (but not necessarily in other languages).
This oddity has an interesting side-effect, however: you can assume that abs
never returns a negative number.