lua-users home
lua-l archive

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


On Thu, Jan 14, 2010 at 3:13 PM, Miles Bader <miles@gnu.org> wrote:
> Mike Pall <mikelu-1001@mike.de> writes:
>> In all the years I've been writing C and assembler I've never had a
>> need to mix left and right shifts controlled by the same variable
>> holding a signed shift count.
>
> I agree.  I think people almost always have a certain shift direction in
> mind, and it's much clearer to explicitly reflect this in the code.
> Use of negation to indicate this seems an obfuscation.

It makes sense to me that rshift can take a negative magnitude, "0xf0
>> -2", I'd even be OK
with only a bit.rshift(), where I had to use a negative to mean "left".

But, I will never be able to remember whether right or left is
positive as an argument to bit.shift().

We will probably continue using bitop in lua 5.2, it works well, and I
don't want to find out
the new bit library subtly breaks our code, but even if I we used the
builtin, I would make a bit.[r/l]shift.

Cheers,
Sam