A question about floating-point precision in Go made me wonder how C handles the problem.
With the following code in C:
float a = 0.1;
Will a
have the closest IEEE 754 binary representation of:
00111101110011001100110011001101 (Decimal: 0.10000000149011612)
or will it just crop it to:
00111101110011001100110011001100 (Decimal: 0.09999999403953552)
Or will it differ depending on compiler/platform?
An implementation is allowed to do either (or even be off by one more):
(C11, §6.4.4.2/3)
Since C99, we've had hexadecimal floating point constants so that you can specify precisely the bits you want (assuming that the implementation offers binary floating point :) ), so you could have said, for example:
For IEEE 754 32-bit floats:
Unspecified by the standard, but testing on some local hardware:
0.1000000014901161