# [Pharo-project] scaled decimal question

Stéphane Ducasse stephane.ducasse at inria.fr
Sun Sep 18 13:09:08 EDT 2011

```On Sep 18, 2011, at 6:21 PM, Peter Hugosson-Miller wrote:

> 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.

sure you are explaining to me why I get a different behavior at the implementation level but my question is at the conceptual level :)

At the end we (the language designer) could make that they are the same because
0 is a character
. too
and 1 too.

So I have no problem that we decide that

0.1 asScaledDecimal: 2
is not the same as 0.1s2 but in that case we call it

0.1 asSomethingElseThanScaledDecimal: 2

and this is perfect for me.

This is all my point. else 2 could be different from 1+1 too :)

Stef

>
> --
> Cheers,
> Peter.
>
> On 18 sep 2011, at 17:59, Stéphane Ducasse <stephane.ducasse at inria.fr> wrote:
>
>>
>> On Sep 18, 2011, at 5:47 PM, Nicolas Cellier wrote:
>>
>>> 2011/9/18 Stéphane Ducasse <stephane.ducasse at 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 at 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 at 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
>>>>>>>
>>>>>>> ?
>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>
>>
>

```