On 5/27/2015 1:29 PM, Nicolas Cellier
wrote:
Totally agree until now :)
I think this is not well formulated and it might actually deepen the
misunderstanding. There is no math to be unlearned. There is just
some extra info that has to be remembered about computers.
I don't think anybody was ever taught in math class that 0.33 equals
1/3. Not even that 0.3333333333333333 equals 1/3. Not even in the US
(although there is a state where a guy introduced a law to change
the value of Pi to 3, to make things simpler :)).
Here we have the same situation. For these particular floats, their
literal value, as expressed in base 10 digits (which is what we do
when we input them in source code), has no exact representation (in
binary, which is how they are actually compiled/stored), so from the
very start these floats are just an approximation. Perhaps the
compiler should warn people every time they write such a literal.
This would be easy to do and I think it would save people a lot of
heartburn.
It is very revealing to look at 0.1 asTrueFraction or at 273.15
asTrueFraction , and then it will become obvious why these floats
are not equal with those fractions.
Whereas if you take the very same base 10 literals, but not in float
format but as scaledDecimals, the comparisons evaluate to true, as
they should:
1/10 = 0.1s and 273.15s = (5463/20).
Florin