3 ms·
> The reason for this is that 1/3 cannot be precisely represented in decimal but (maybe somewhat surprisingly) it can be in binary, hence the correct result for
by tzs 10y ago
> The reason for this is that 1/3 cannot be precisely represented in decimal but (maybe somewhat surprisingly) it can be in binary, hence the correct result for 1/3 + 1/3 + 1/3 = 1.
1/3 cannot be precisely represented in (finite) binary. Its representation is 0.0̅1̅.
- weinzierl 10y agoThanks, you are right, see my comment to dragonwriter also.
- deleted 10y ago[deleted]
- tzs 10y ago(This was meant to be appended as an edit to the above, but between the time I started typing it into the update text area and the time I hit the "update" button the comment aged enough to not allow updates, so I'll add it as a reply) In general, a necessary (but not sufficient) condition for the representation of n/m to be precisely represented in base b is that there exists some integer r in [1, m-1] such that rb = 0 mod m. If you work out the representation of n/m using the classic division algorithm, the algorithm terminates iff you hit such an r after one of the subtraction steps. The step on which you hit that r will have produced the next to less digit of the result, and then the algorithm will product one more digit and terminate. When m is a prime (such as m = 3), then (r, m) = 1, and so rb = 0 mod m is only possible if b = 0 mod m. If b = 0 mod m then all r are suitable, and n/m has at most one digit after the radix point.