[squeak-dev] 2 raisedTo: 63 on Pi returns 0 ? (was Re: how to determine available RAM?)
David T. Lewis
lewis at mail.msen.com
Fri May 7 22:22:18 UTC 2021
On Thu, May 06, 2021 at 04:33:55PM -0700, tim Rowledge wrote:
> I was just about to say something about Chris'question and tried
>
> 2 raisedTo: 63
>
> in a Workspace. I was a little surprised to see '0' returned.
>
> On my Mac 64 I get the right answer. On the Pi I get the right(ish) answer if I substitute 2.0. To make things weirder if I debug, the end value of 'result' in Number>>#raisedToInteger: is correct. The value of 'stack top' in its sender #raisedTo: is the same correct value.
>
> Gronk? It's clearly not a problem with printing the value since I see the correct value. If I try
> (2 raisedTo: 63) / 64.0
> to check what number is actually there... I get 0. Implying there is really 0. Debug it and.. yup 0. What? It looks like somewhere the LPI instance is getting mishandled but where?
>
Whatever the issue turns out to be, we need to turn it into a unit
test in trunk. It's a serious failure that is very easy to overlook.
It only takes 8 passes through the look in Number>>raisedToInteger:
to get to the solution, so you should be able to use a debugger to
see where things are going wrong. Or print to Transcript and see
where it fails.
For example if I use this:
Number>>raisedToInteger: anInteger
"The 0 raisedToInteger: 0 is an special case. In some contexts must be 1 and in others must
be handled as an indeterminate form.
I take the first context because that's the way that was previously handled.
Maybe further discussion is required on this topic."
| bitProbe result |
anInteger negative ifTrue: [^(self raisedToInteger: anInteger negated) reciprocal].
bitProbe := 1 bitShift: anInteger highBit - 1.
result := self class one.
[
Transcript showln: 'TOP LOOP ', result asString, ' BITPROBE ', bitProbe asString.
(anInteger bitAnd: bitProbe) > 0 ifTrue: [ result := result * self ].
(bitProbe := bitProbe bitShift: -1) > 0 ]
whileTrue: [ result := result squared .
Transcript showln: 'INNER LOOP ', result asString].
^result
Then the (good) output on the Transcript is:
TOP LOOP 1 BITPROBE 32
INNER LOOP 4
TOP LOOP 4 BITPROBE 16
INNER LOOP 64
TOP LOOP 64 BITPROBE 8
INNER LOOP 16384
TOP LOOP 16384 BITPROBE 4
INNER LOOP 1073741824
TOP LOOP 1073741824 BITPROBE 2
TOP LOOP 1 BITPROBE 8
INNER LOOP 100
TOP LOOP 100 BITPROBE 4
INNER LOOP 10000
TOP LOOP 10000 BITPROBE 2
INNER LOOP 100000000
TOP LOOP 100000000 BITPROBE 1
INNER LOOP 4611686018427387904
TOP LOOP 1 BITPROBE 8
INNER LOOP 100
TOP LOOP 100 BITPROBE 4
INNER LOOP 10000
TOP LOOP 10000 BITPROBE 2
INNER LOOP 100000000
TOP LOOP 100000000 BITPROBE 1
TOP LOOP 4611686018427387904 BITPROBE 1
If you run the same thing on the Pi VM, I expect you will see something quite different.
Dave
More information about the Squeak-dev
mailing list
|