I suppose I'll have to stand corrected. I got confused by the
conversion in the other direction (ie. not all values in base
10 can be represented as floating point of base 2).
Only if you use the exponential notation (ie.
"<base>e<exponent>"). If you wrote it as a decimal value, it
could take hundreds of digits (after all, the maximum value of
a double-precision floating point is something like 10^300).
Good point. But it's worse than you think: the generated
notation has nothing to do with; the only important part is the
actual value. For an IEEE double:
-- If the value is between 0.5 and 1.0 (logical exponent 0),
the value can be written exactly in at most 53 digits, for
the reason I explained.
-- If the value is larger than 2^53, the exact value is an
integer. Since DBL_MAX is something e307, it takes at most
307 digits. On the other hand, the value can be 2^1023
(even larger in fact, but less than 2^1024), and 2^1023
requires 308 digits to represent exactly. (The value is
roughly 9e307, and is not a multiple of 10, so will require
a units digit which is not 0.) Thus, there are values which
require 308 digits.
-- For exponents less than 0, I'm too lazy to do the exact
analysis, but I get the feeling that they will never require
more digits than 308. Unlike positive values, increasing
the binary exponant quickly starts introducing 0's to the
right of the decimal. I'll leave the detailed analysis and
the proof to others, but I'm fairly convinced that it can't
be worse than 308 + 53. Which is still a finit number of
digits.