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

Levente Uzonyi leves at elte.hu
Mon Jul 11 20:15:11 UTC 2011


On Mon, 11 Jul 2011, Igor Stasenko wrote:

> Levente, your change is a bit dangerous,
> because if i remember correctly, not all primitives normalizing large integers.
> So, it is fairly possible to have large integer with value in a range
> of small integer.

Try these:

0 digitCompare: (LargePositiveInteger new: 4).
(LargePositiveInteger new: 4) digitCompare: 0.
(LargePositiveInteger new: 4) digitCompare: (LargePositiveInteger new: 3)
(LargePositiveInteger new: 3) digitCompare: (LargePositiveInteger new: 4)
etc.

#digitCompare: assumes normalized Integers, so nothing is broken by this 
change. As Nicolas pointed out, the users of those primitives are 
responsible for normalizing the numbers before evaluating "dangerous" 
methods with them.


Levente

>
> Not saying , that one can manipulate largeinteger bits directly, and
> then use it later in comparison,
> which will fail due to your changes.
> So, such change requiring strong guarantees that you cannot create
> large integers which is in range of small integers.
>
> On 10 July 2011 16:36,  <commits at source.squeak.org> wrote:
>> Levente Uzonyi uploaded a new version of Kernel to project The Trunk:
>> http://source.squeak.org/trunk/Kernel-ul.604.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Kernel-ul.604
>> Author: ul
>> Time: 10 July 2011, 4:36:20.467 pm
>> UUID: f758876f-a507-404b-aa2f-2c1038504b48
>> Ancestors: Kernel-bf.603
>>
>> Optimized Integer >> #= for integer-integer comparisons. Return false for integers from different classes without further checking.
>>
>> =============== Diff against Kernel-bf.603 ===============
>>
>> Item was changed:
>>  ----- Method: Integer>>= (in category 'comparing') -----
>>  = aNumber
>> +
>> +       aNumber isInteger ifTrue: [
>> +               aNumber class == self class ifFalse: [ ^false ].
>> +               ^(self digitCompare: aNumber) = 0 ].
>> +       aNumber isNumber ifFalse: [ ^false ].
>> +       ^aNumber adaptToInteger: self andCompare: #=!
>> -       aNumber isNumber ifFalse: [^ false].
>> -       aNumber isInteger ifTrue:
>> -               [aNumber negative == self negative
>> -                       ifTrue: [^ (self digitCompare: aNumber) = 0]
>> -                       ifFalse: [^ false]].
>> -       ^ aNumber adaptToInteger: self andCompare: #=!
>>
>>
>>
>
>
>
> -- 
> Best regards,
> Igor Stasenko AKA sig.
>
>


More information about the Squeak-dev mailing list