[squeak-dev] The Trunk: Kernel-ul.485.mcz

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Mon Aug 23 18:50:03 UTC 2010


2010/8/23 Levente Uzonyi <leves at elte.hu>:
> On Mon, 23 Aug 2010, Nicolas Cellier wrote:
>
>> Waouh!
>>
>> I don't know how you could possibly find this one!
>> Chapeau bas
>
> It was just an "accident". There was a discussion on the Pharo list about
> converting a ByteArray to an Integer. Since LargeIntegers are
> variableByteSubclasses (just like ByteArrays), I tried this:
> #[1] as: LargePositiveInteger.
> The printString was empty without #normalize, so I started debugging. It's a
> bit strange though, that LargePositiveInteger >> #printOn:base: has the
> following lines:
> "Don't engage any arithmetic if not normalized"
> (self digitLength = 0 or: [(self digitAt: self digitLength) = 0]) ifTrue:
> [^self normalize printOn: aStream base: b].
> But the "artifically created" not normalized LargePositiveInteger passes
> this check.
>

Ah, I see, nice trick...
Does it deserve a dedicated test, or is it too fragile a feature ?

Nicolas

>
> Levente
>
>>
>> Nicolas
>>
>> 2010/8/23  <commits at source.squeak.org>:
>>>
>>> Levente Uzonyi uploaded a new version of Kernel to project The Trunk:
>>> http://source.squeak.org/trunk/Kernel-ul.485.mcz
>>>
>>> ==================== Summary ====================
>>>
>>> Name: Kernel-ul.485
>>> Author: ul
>>> Time: 23 August 2010, 2:13:52.357 pm
>>> UUID: fce08992-f821-ed46-a863-9935d6a7fe2e
>>> Ancestors: Kernel-dtl.484
>>>
>>> - fix LargeInteger printing
>>>
>>> =============== Diff against Kernel-dtl.484 ===============
>>>
>>> Item was changed:
>>>  ----- Method: LargePositiveInteger>>printOn:base:nDigits: (in category
>>> 'printing') -----
>>>  printOn: aStream base: b nDigits: n
>>>        "Append a representation of this number in base b on aStream using
>>> n digits.
>>>        In order to reduce cost of LargePositiveInteger ops, split the
>>> number of digts approximatily in two
>>>        Should be invoked with: 0 <= self < (b raisedToInteger: n)"
>>>
>>>        | halfPower half head tail |
>>>        n <= 1 ifTrue: [
>>>                n <= 0 ifTrue: [self error: 'Number of digits n should be
>>> > 0'].
>>>
>>>                "Note: this is to stop an infinite loop if one ever
>>> attempts to print with a huge base
>>>                This can happen because choice was to not hardcode any
>>> limit for base b
>>>                We let Character>>#digitValue: fail"
>>> +               ^aStream nextPut: (Character digitValue: self) ].
>>> -               ^Character digitValue: self].
>>>        halfPower := n bitShift: -1.
>>>        half := b raisedToInteger: halfPower.
>>>        head := self quo: half.
>>>        tail := self - (head * half).
>>>        head printOn: aStream base: b nDigits: n - halfPower.
>>>        tail printOn: aStream base: b nDigits: halfPower!
>>>
>>>
>>>
>>
>
>
>
>



More information about the Squeak-dev mailing list