[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: [ANN] Lua 5.3.0 (work2) now available**
**From**: Roberto Ierusalimschy <roberto@...>
**Date**: Wed, 26 Mar 2014 12:30:28 -0300

> > The argument becomes "Having an algorithm that needs changed
> > for Lua, Perl and Free Pascal and those languages alone is the
> > violation of the principle of least surprise". Not quite so convincing
> > any more, especially as quite a few langages have not been
> > tested yet by either party to the debate.
>
> It should also be noted that to classify Python shifts as "arithmetic
> shifts" is not very precise, because Python does not have fixed-width
> integers. It seems more precise to say that Python is like C, with
> logical shifts for unsigned integers and arithmetic shifts for signed
> integers:
>
> x = 0xffffffffffffffff
> print(x, x >> 1) --> (18446744073709551615L, 9223372036854775807L)
>
> x = -1
> print(x, x >> 1) --> (-1, -1)
>
> Very elegant BTW (but expensive). Knuth uses something similar in
> his book of bit tricks (negative numbers have infinite 1's to the
> left).
One more clarification: C# also does not agree that >> is an arithmetic
shift. It follows C (but with proper documentation), in that >> can
be logical or arithmetic, depending on the type of its left operand.
-- Roberto