Replace
#define INT32_MIN (-2147483648L)
with
#define INT32_MIN (-2147483647 - 1)
-2147483648
is interpreted by the compiler to be the negation of 2147483648
, which causes overflow on an int
. So you should write (-2147483647 - 1)
instead.
This is all C89
standard though. See Steve Jessop’s answer for C99
.
Also long
is typically 32 bits on 32-bit machines, and 64 bits on 64-bit machines. int
here gets the things done.