On Sep 18, 2011, at 5:47 PM, Nicolas Cellier wrote: > 2011/9/18 Stéphane Ducasse <stephane.duca...@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 <oldmanl...@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.duca...@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 >>>>> >>>>> ? >>>> >>>> >>> >> >> >> >