I just started reading Hacker\'s Delight and it defines abs(-231) as -231. Why is that?
I tried printf(\"%x\", abs(0x80000000))
on a f
Because integers are stored in memory as a two's complement binary number, the positive version of the minimum value overflows back to negative.
That is to say (in .NET, but still applies):
int.MaxValue + 1 == int.MinValue // Due to overflow.
And
Math.Abs((long)int.MinValue) == (long)int.MaxValue + 1