I have a program in C like this:
#include <stdio.h>
int main() {
float number = 0;
scanf("%f", &number);
printf("%f\n", number);
}
And the output is:
ururay@note:~/workspace/c/float-precision$ gcc float-precision.c -o float-precision
ururay@note:~/workspace/c/float-precision$ ./float-precision
5456.367
5456.367188
I have executed this program several times and the output is the same. Is the ‘188’ "appended" to the end of the number because float precision? If so, how could I identify this in binary representation?
>Solution :
The number 5456.367 cannot be represented exactly in the IEEE-754 single-precision floating point format.
The closest number is 5456.3671875, which has the binary representation 01000101101010101000001011110000. The next smaller representable number is 5456.3666992, which has the binary representation 01000101101010101000001011101111.