Reputation: 13
0.2 cannot be represented in floating point because the conversion of 0.2 to binary is repeating. But why cant the right side of the decimal just be treated as an integer when converting to binary? I.e. 0.2 would be 0.10 in binary because 0 would convert to 0 and 2 would convert to 10?
Upvotes: 1
Views: 115
Reputation: 26185
What you are describing seems close to some floating point systems such as Java's BigDecimal. It stores numbers as the combination of an integer and a decimal scale factor.
That sort of system is useful if exact representation of decimal fractions is especially important. That is, if exact representation of 1/5 is much more important than exact representation of 1/3.
The big advantage of binary floating point is that it can give a very compact representation that lends itself to hardware arithmetic and register storage.
Upvotes: 1