Joe Wright said:
The 24-bit mantissa of the float demands 8 decimal digits for its
representation. The 53-bit double mantissa demands 16 decimal digits.
I had occasion, some time ago, to express float and double as text
and then from text back to float and double. Exactly.
Given a double, text is..
char buf[30]; /* more than enough */
sprintf(buf, "%.16e", dbl);
For a float..
sprintf(buf, "%.8e", flt);
Now use of atof() or strtod() will take the text back to floating
point. Exactly.
Hmmm -- it is not obvious to me that exact conversion will happen in
that case, Joe. 8 or 16 decimal digits gets you to the point at which
you can precisely pin down the last decimal digit displayed, but there
may have been up to around 3 additional bits worth of information
stored without being able to select the precise decimal digit for output.
For example, the system might know that the bottom 3 bits are 011, but
be unable to decide whether to output a 4 (.375 rounded up through
((.45 minus epsilon) rounded down), or a 5 (.45 rounded up through
((.5 minus epsilon) rounded down)). The alternative is to print out
more digits than are really present, in order to get enough
information to fill the bottom bits.