lua-users home
lua-l archive

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


On Mar 25, 2014, at 10:07 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:

> 2014-03-25 18:20 GMT+02:00 Paul Baker <paulbaker8@gmail.com>:
> 
>> Regarding the new bitwise operators, the Reference Manual states "Both
>> right and left shifts fill with zeros the vacant bits". Given that
>> "Lua 5.3 has integers but not unsigned integers" [1], it seems strange
>> that the >> operator is unsigned rather than signed. Is there a reason
>> for this? Personally, I think it would be useful for Lua to support
>> both types of right shift - perhaps using the same syntax as
>> JavaScript: >> and >>> ?
> 
> Don't agree.
> 
> I can see the point of arithmetic shift in C, where it could be useful
> when programming multiprecision arithmetic — but C does not have
> it. Its inclusion in the bit32 library always felt to me like a loving
> preservation of a quirk of some early computer (IBM 360 springs to
> mind).
> 

I’m not sure I can think of a need for arithmetic shift off the top of my head, but I’m always leery of the “I can’t think of a reason .. so there isn’t one” style of argument. And in fact I have used arithmetic shift on quite a few occasions over the years, but almost never for multi precision arithmetic.

—Tim