C: Casting minimum 32-bit integer (-2147483648) to float gives positive number (2147483648.0)

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 … Read more