[Cuis-dev] Bug in Integer>>#raisedTo:modulo:

Luciano Notarfrancesco luchiano at gmail.com
Mon Jun 5 10:09:37 PDT 2023


Ah, good to know, you replaced all calls to \\\ with \\ in all methods or
only this one? We should do the same in Cuis. Still, the randomness mystery
remains…

On Mon, 5 Jun 2023 at 19:04 Nicolas Cellier via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:

> Ah OK... I expunged the sends of \\\ operator from Squeak.
> This is exactly like \\ but omits normalization of LargeInteger result...
> Below is the comment that i let in \\\ definition:
>
>
> "A modulo method former used in DSA."
>
> "Notes: this method used to be a faster than \\ for LargeIntegers, but
> this advantage is fainting:
> - it always was slower for SmallInteger because of the indirection below
> - a new LargeInteger primitive makes \\ faster up to 64 bits operands
> - even above 64 bits, its advantage has become marginal thanks to revised
> \\ primitive fallback code
> Moreover, \\\ behaviour is questionable for these reasons:
> - for a negative receiver xor argument, it behaves like rem: for
> LargeInteger and \\ for SmallInteger
> - it may answer a not normalized LargeInteger (with leading null digits)
> which breaks some invariants
> For example, check (SmallInteger maxVal + 1 \\\ 8) isZero.
> So beware if you ever think using this method."
>
>
> Le lun. 5 juin 2023 à 18:56, Luciano Notarfrancesco via Cuis-dev <
> cuis-dev at lists.cuis.st> a écrit :
>
>> Doing
>>     pow := pow * pow \\ m
>> instead of
>>     pow := pow * pow \\\ m
>> at the beginning of the loop in
>> Integer>>#slidingLeftRightRaisedTo:modulo: seems to fix it. But still I’m
>> not sure why it is random otherwise, and I’m not sure that this really
>> fixes the problem.
>>
>>
>> On Mon, 5 Jun 2023 at 18:42 Luciano Notarfrancesco <luchiano at gmail.com>
>> wrote:
>>
>>> The following:
>>>     5445648384 raisedTo: 3 modulo: 1 << 34
>>> Returns 0, which is right. But
>>>     5445648384 raisedTo: 4 modulo: 1 << 34
>>> Returns different numbers every time I call it (it should return 0).
>>> It’s very weird… I don’t see where the randomness is coming from,
>>> perhaps from LargeIntegerPlugin?
>>>
>>>
>>> --
>> Cuis-dev mailing list
>> Cuis-dev at lists.cuis.st
>> https://lists.cuis.st/mailman/listinfo/cuis-dev
>>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230605/54da96e8/attachment.htm>


More information about the Cuis-dev mailing list