lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> > 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