Thanks David for the fix. Very nice that the Smalltalk primitive can just fail when the shift amount is too large.
Bert Freudenberg wrote:
Indeed. Not just C though. In JavaScript I discovered that (42 << 32) == 42.
Thanks Bert.
Also confirmed on Google Chrome 36.0 (V8 3.26) and Node v0.10.
Right shift is the same (42 >> 32) == 42. And (42 >> 35) == 5
Did you have to work around it when designing SqueakJS ? My guess is not: I guess that the SqueakJS VM is a purely 32 bit machine, and that this behaviour won't affect Smalltalk programs.
Have fun! David
p.s.
I wonder if this is a restriction imposed by the language standard, or is merely a side effect of a common implementation choice. The MDN reference page says "Bitwise operators treat their operands as a sequence of 32 bits". Which, with hindsight, leaves shifts of more than 31 bits undefined. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/...
However, my naive reading of this paragraph of the ECMAScript 5 standard suggests that wrapping around a bit shift is just plain wrong, and that it should yield 0 or fail (until a 64 bit Javascript standard is written) http://www.ecma-international.org/ecma-262/5.1/#sec-11.7