Fw: bit shifting
caniglia at mate.dm.uba.ar
Sun Apr 12 23:04:54 UTC 1998
Hans-Martin Mosner wrote:
>has anybody else discovered that bit shifting of negative numbers is
>broken? Although the comment in Integer>>bitShift: says that it shifts
>the two's complement, it's actually doing one's complement shifting,
> (-1 bitShift: 1) = -2
>which is plain wrong. Unfortunately, if I correct the
>SmallInteger>>bitShift: method, LargeInteger division breaks. And I
>don't want to mess with Integer>>digitDiv:neg: !
I remember some discusion about this problem one year ago or so, initiated
by David N. Smith. The patch of Dave appeared to be OK, but it produced some
bad side efect in multiplications :-(
1. In my 1.31 (-1 bitShift: 1) evaluates to -1 (not -2).
2. To my understanding (-1 bitShift: 1) = -2 is OK since -1, in a
multiprecision binary representation, is ........11111111. So, shifting it
one place to the left gives
.........11111110 which equals -2. If I'm wrong, pleace let me know.
More information about the Squeak-dev