[squeak-dev] ScaledDecimal newFromNumber: 0.0 scale: 0 can't print

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Wed Sep 7 19:33:11 UTC 2011


2011/9/7 Frank Shearar <frank.shearar at gmail.com>:
> On 7 September 2011 18:24, Nicolas Cellier
> <nicolas.cellier.aka.nice at gmail.com> wrote:
>> Oops, it was in my image where Integer canUnderstand: #denominator,
>> does not seem the case in a base image ?
>
> I can confirm that Integer does not understand #denominator in trunk.
> It wouldn't be crazy to just have
>
> Integer denominator [
>    ^ 1.
> ]
>
> and, if necessary,
>
> Integer numerator [
>    ^ self
> ]
>
> frank
>

Absolutely, VW does, gst does,
http://www.gnu.org/software/smalltalk/manual-base/html_node/Integer_002daccessing.html#Integer_002daccessing,
I don't know why I was so sure Squeak did too.

>> Nicolas
>>
>> 2011/9/7 Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>:
>>> And I just checked, and:
>>>
>>> 1) the senders of isFraction would work equally well if
>>> Integer>>isFraction did answer true.
>>>  This is because they only expect the fraction to answer to
>>> #numerator and #denominator, and Integer does that quite well
>>> 2) this would fast up mixed Integer/Fraction arithmetic.
>>>
>>> 3) the senders of asFraction that really expect a Fraction are
>>> * Fraction>>adaptToInteger: rcvr andSend: selector
>>> * Integer>>adaptToFraction: rcvr andSend: selector
>>> But the later would be useless if Integer>>isFraction did answer true.
>>> 4) the other senders of #asFraction are in ScaledDecimal and don't
>>> care whether the Fraction really is a Fraction or an Integer
>>>
>>> So it might be time to enforce this peculiarity:
>>> Integer>>isFraction
>>>    "Answer true because every Integer is polymorphic with a Fraction."
>>> Integer>>asFraction
>>>    "See Integer>>#isFraction."
>>>    ^self
>>>
>>> Nicolas
>>>
>>> 2011/9/7 Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>:
>>>> OK, I had a chance to open an image and I see I'm responsible for this problem.
>>>> Levente changed the printing method, I recognized an already existing
>>>> Fraction>>printTruncatedOn:showingDecimalPlaces: and decided to use
>>>> it. But this message is not Integer friendly indeed.
>>>>
>>>> Otherwise, there is no problem if the fraction ivar is an Integer, it
>>>> alerady was before, and can continue to be, as long as Integer
>>>> instances are polymorphic to Fraction (what they mostly are).
>>>> I gonna correct the mess this evening, thanks for reporting!
>>>>
>>>> Nicolas
>>>>
>>>>
>>>> 2011/9/7 Frank Shearar <frank.shearar at gmail.com>:
>>>>> On 7 September 2011 12:32, Nicolas Cellier
>>>>> <nicolas.cellier.aka.nice at gmail.com> wrote:
>>>>>> Isn't it also the case with (ScaledDecimal newFromNumber: 1.0 scale: 0) ?
>>>>>
>>>>> It's true for any integral-valued float. Somewhere near the bottom of
>>>>> Float >> #asTrueFraction the line
>>>>>
>>>>>  result := signedFraction bitShift: zeroBitsCount negated
>>>>>
>>>>> returns an Integer.
>>>>>
>>>>> Presumably (and I'm really just guessing here), we could say
>>>>>
>>>>>    result := Fraction
>>>>>        numerator: (signedFraction bitShift: zeroBitsCount negated)
>>>>>        denominator: 1
>>>>>
>>>>> frank
>>>>>
>>>>>> 2011/9/7 Frank Shearar <frank.shearar at gmail.com>:
>>>>>>> Evaluate the following:
>>>>>>>
>>>>>>> 0s0 "=> 0s0"
>>>>>>> ScaledDecimal newFromNumber: 0 scale: 0 "=> 0s0"
>>>>>>>
>>>>>>> 0.0s0 "=> 0s0"
>>>>>>> ScaledDecimal newFromNumber: 0.0 scale: 0 "=> MNU: SmallInteger
>>>>>>> doesn't understand printTruncatedOn:showingDecimalPlaces:"
>>>>>>>
>>>>>>> The MNU happens because in ScaledDecimal class >> #newFromNumber:scale: we say
>>>>>>>
>>>>>>>    "..." aNumber asFraction "..."
>>>>>>>
>>>>>>> and when aNumber = 0.0, aNumber asFraction = 0, which is a
>>>>>>> SmallInteger and not a Fraction.
>>>>>>>
>>>>>>> (Recorded as http://bugs.squeak.org/view.php?id=7667)
>>>>>>>
>>>>>>> frank
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>>
>
>



More information about the Squeak-dev mailing list