Hacker News new | ask | show | jobs
by Jasper_ 1467 days ago
My attempt: You can't express 1/3, 1/6, 1/7, or 1/9 in decimal without infinitely repeating digits; you can only express 1/2 and 1/5, and 2*5=10. In binary systems, you can only represent multiples of 1/2 without infinite repeating digits, so, 0.5, 0.25, 0.125 are all exact in binary floating point. 0.1 is 1/10, which needs that 5 you don't have in binary. Computers don't have infinite memory, so infinitely repeating digits are truncated at some point. As such, 0.1 + 0.2 in binary floating point is not exact, the same way adding 0.33333 + 0.66666 wouldn't exactly give you 1.0 in decimal.
1 comments

This is pretty good for illustration to a layperson, thank you! Filling in a few other examples could be useful. For instance, why do 1/4 and 1/8 work in base-10?

I imagine you could create a table of the fractions 1/2, 1/3, ..., 1/10; prime factorization (e.g. 1/4 = 1/2 * 1/2), their decimal representation, their binary representation, and maybe for familiarity the sum-of-fractions represented by the binary representation. e.g. 0.101 meaning 1/2 + 1/8.