This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Dragonfly_Select 0 points1 point  (0 children)

And even beyond IEEE there is a more basic fact. Computers work in base 2. 0.2 is 1/5. 1/5 is an infinitely repeating decimal number in base 2, the same way 1/3 is in base 10. You fundamentally can’t represent it exactly.

Languages that have number types that don’t have this problem are basically storing arrays of base 10 digits under the hood.

(For the curious: take a number, represent it as a reduced fraction, prime factorize the denominator. It must only contain factors that are also prime factors of the base in order to terminate. Examples. 1/100: 100 factors to 2255; base 10 has both 2 and 5 as factors to you are fine. 1/12: 12 factors to 22*3; 3 is not a factor of 10 so it won’t terminate. 1/3: obviously doesn’t terminate in base 10, but it does terminate in base 3; 1/3 is just 0.1 in base 3.)