Strange behavior when casting an int to float in C
I have a doubt concerning the output of the following C program. I tried to compile it using both Visual C++ 6.0 and MinGW32 (gcc 3.4.2). #include <stdio.h> int main() { int x = 2147483647; printf("%f\n", (float)2147483647); printf("%f\n", (float)x); return 0; } The output is: 2147483648.000000 2147483647.000000 My question is: why are both lines different? When you convert the integer value 2147483647 to the IEEE 754 floating-point format, it gets approximated to 2147483648.0. So, I expected that both lines would be equal to 2147483648.000000. EDIT : The value "2147483647.000000" can't be a