On Sep 18, 2011, at 6:25 PM, Nicolas Cellier wrote:
And in Squeak 3.7, I just verified that (Number class>>readFrom:) did use an intermediate Float...
0.1s2 asFraction -> (3602879701896397/36028797018963968)
This was corrected in 3.8, so maybe not integrated by you Stef ?
you confused me :) Should we integrate something in pharo? Stef
Nicolas
2011/9/18 Peter Hugosson-Miller <oldmanlink@gmail.com>:
Yeah, but the *big* difference is that "asScaledDecimal: 2" is a message sent to a Float, whereas the "s2" is just part of the literal representation of a ScaledDecimal, and *not* a message sent to anything.
-- Cheers, Peter.
On 18 sep 2011, at 17:59, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
On Sep 18, 2011, at 5:47 PM, Nicolas Cellier wrote:
2011/9/18 Stéphane Ducasse <stephane.ducasse@inria.fr>:
For me the problem is that if
"s2" means scaled decimal then I do not understand why asScaledDecimal produce objects with different properties.
a number is a scaled decimal or not.
There is a difference between these two:
(1/10) asScaledDecimal: 2. (1/10) asFloat asScaledDecimal: 2.
That I can understand Float is inexact. No problem with that.
Now I do not understand how 0.1s2 relates to the above expressions.
asFloat introduces a rounding error. Though the result prints 0.1, it is different from (1/10), asFrank said, just convert it back asTrueFraction, and you'll see. asScaledDecimal: does not undo the rounding error, it just uses asTrueFraction. If you want to undo the error, you may try (0.1 roundTo: 0.01s2).
Nicolas
On Sep 18, 2011, at 10:36 AM, Frank Shearar wrote:
On 17 September 2011 14:06, Peter Hugosson-Miller <oldmanlink@gmail.com> wrote:
Probably because Floats are not exact, so the result of #asScaledDecimal: when sent to a Float, differs from what the compiler produces when it parses 0.1s2.
Sure I guessed that too but I hate this behavior.
Indeed. In particular, the Floats turn themselves into "exact representations" (Float >> #asTrueFraction) - Fractions whose bit patterns duplicate the float representation. That means that the resulting ScaledDecimals (0.1s2 + 0.2s2 and 0.3s2) have differing fraction instvars.
frank
-- Cheers, Peter.
On 17 sep 2011, at 15:01, Stéphane Ducasse <stephane.ducasse@inria.fr> wrote:
Why (0.1 asScaledDecimal: 2) + (0.2 asScaledDecimal: 2) = (0.3 asScaledDecimal: 2) returns false
while
0.1s2 + 0.2s2 = 0.3s2 returns true
?