<div><div dir="auto">Oh, you’re totally right, I see now! (For a moment I thought you just added bitReverse: in LargePositiveInteger and I forgot it was originally implemented there as well, I couldn’t understand how the method in Integer could ever fail.) Thanks for taking the time to debug it!</div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 24 Jun 2020 at 10:36 PM, Juan Vuletich via Cuis-dev <<a href="mailto:cuis-dev@lists.cuis.st">cuis-dev@lists.cuis.st</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><u></u>
<div bgcolor="#ffffff" text="#000000"></div><div bgcolor="#ffffff" text="#000000">
On 6/24/2020 11:34 AM, Luciano Notarfrancesco via Cuis-dev wrote:
<blockquote type="cite">
<div>
<div dir="auto">But that means that at some point a bit
operation (bitShift, bitOr, bitAnd) answers a LargeInteger
that actually fits in a SmallInteger, right? That should never
happen, because for example equality fails.</div>
</div>
<div><br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, 24 Jun 2020 at 9:28
PM, Juan Vuletich <<a href="mailto:juan@jvuletich.org" target="_blank">juan@jvuletich.org</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">
<div bgcolor="#ffffff" text="#000000"> On 6/23/2020 10:58
AM, Luciano Notarfrancesco via Cuis-dev wrote:
<blockquote type="cite">
<div>
<div dir="auto">Sorry, should be whileTrue there...</div>
</div>
<div><br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, 23 Jun
2020 at 8:57 PM, Luciano Notarfrancesco <<a href="mailto:luchiano@gmail.com" target="_blank">luchiano@gmail.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">
<div dir="auto">Try this in a workspace:</div>
<div dir="auto"><br>
</div>
<div dir="auto">[a _ (1 << 60) atRandom.</div>
<div dir="auto">b _ (a bitReverse: 64) bitReverse:
64.</div>
<div dir="auto">a = b] whileFalse</div>
<div dir="auto"><br>
</div>
<div dir="auto">I tested it in the latest image
with a recent cog spur x64 VM. The loop stops
with a ‘b’ that is a LargePositiveInteger but it
actually fits in a SmallInteger and it is equal
to ‘a’. I don’t have time to debug it until the
weekend but I thought someone might find it
amusing.</div>
</blockquote>
</div>
</div>
</blockquote>
<br>
</div>
<div bgcolor="#ffffff" text="#000000"> Well, this was fun!<br>
<br>
When you find the problem (the primitive in
#bitShiftMagnitude: answers the receiver if the argument
is zero, without reducing it to SmallInteger as
appropriate), and you try to fix it, then, when you want
to write a test that fails without the fix, you can not
make it fail!<br>
<br>
The problem only happens when #bitReverse: gets jitted by
the Cog VM, and that requires a few runs to happen. Hence,
the test loops a few times, doing exactly the same.<br>
<br>
Please take a look.<br>
<br>
Cheers,<br>
<pre style="font-family:monospace" cols="72">--
Juan Vuletich
<a href="http://www.cuis-smalltalk.org" style="font-family:monospace" target="_blank">www.cuis-smalltalk.org</a>
<a href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev" style="font-family:monospace" target="_blank">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev</a>
<a href="https://github.com/jvuletich" style="font-family:monospace" target="_blank">https://github.com/jvuletich</a>
<a href="https://www.linkedin.com/in/juan-vuletich-75611b3" style="font-family:monospace" target="_blank">https://www.linkedin.com/in/juan-vuletich-75611b3</a>
@JuanVuletich</pre>
</div>
</blockquote>
</div>
</div>
</blockquote>
<br></div><div bgcolor="#ffffff" text="#000000">
Take a look at the code!<br>
<br>
In LargePositiveInteger >> bitReverse: it builds a
LargePositiveInteger. Before answering the result, it calls
#bitShiftMagnitude: . As I told above, the primitive in
#bitShiftMagnitude: answers the receiver if the argument is zero,
without reducing it to SmallInteger as appropriate. That's not
unreasonable. #bitShiftMagnitude: can assume the receiver is a sane
instance. The fix I included is to call #normalize as appropriate,
instead of calling #bitShift: when the argument is zero.</div><div bgcolor="#ffffff" text="#000000"><br>
<br>
<pre cols="72" style="font-family:monospace">--
Juan Vuletich
<a href="http://www.cuis-smalltalk.org" target="_blank" style="font-family:monospace">www.cuis-smalltalk.org</a>
<a href="https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev" target="_blank" style="font-family:monospace">https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev</a>
<a href="https://github.com/jvuletich" target="_blank" style="font-family:monospace">https://github.com/jvuletich</a>
<a href="https://www.linkedin.com/in/juan-vuletich-75611b3" target="_blank" style="font-family:monospace">https://www.linkedin.com/in/juan-vuletich-75611b3</a>
@JuanVuletich</pre>
</div>
-- <br>
Cuis-dev mailing list<br>
<a href="mailto:Cuis-dev@lists.cuis.st" target="_blank">Cuis-dev@lists.cuis.st</a><br>
<a href="https://lists.cuis.st/mailman/listinfo/cuis-dev" rel="noreferrer" target="_blank">https://lists.cuis.st/mailman/listinfo/cuis-dev</a><br>
</blockquote></div></div>