Please check: http://stackoverflow.com/questions/33474705/redis-lua-bit-overflow
I would like to use highly performant bit operations on numbers up to 53 bits in length but with current implementation of bit library it's not possible
Comment From: antirez
The version of Lua we use is kinda terrible and had no concept of integer type. Fortunately if I remember correctly now Lua is going to have proper integers. I hope that after Lua and Javascript, nobody will design again a language with just floats. Btw, even with floats, 53 bits is what we should get, so there is some kind of other problem probably. I'll investigate and fix it. Thanks.
Comment From: let4be
Thank you very much @antirez Afaik current bit.* operations are limited to just 30 bits, it starts to overflow right after this value... I'm currently trying to circumvent it by storing the value in 2 variables(high, low) and performing operations separately
Comment From: badboy
Not a problem per se, but a limitation of the library: it uses 32 bit signed integers internally for the reasons written down here
In short: works everywhere, reliable, in any environment. Considering the fact that we control the environment that it is used in we might patch the lib to use unsigned integers
Comment From: antirez
In the documentation there is the following sentence:
It's desirable to define semantics that work the same across all platforms. This dictates that all operations are based on the common denominator of 32 bit integers.
I don't think this is correct, unless I'm missing something of course. Basically even if the target environment is 32 bit, by using a int64_t type, to capture the 53 bit integer part of the double, performing operations, and then converting back to double, should always work the same everywhere.
Maybe the author is willing to target environments where a standard 64 bit type does not exist at all?
Comment From: dpino
I arrived here following the thread from SOF.
Lua 5.3 supports 64-bit integers and provides bitwise operations natively in the language so it's not necessary to use an external module.
http://www.lua.org/manual/5.3/readme.html
This BitOp module is programmed by Mike Pall and it's used mostly in LuaJIT. I don't know if you're using PUC-Rio Lua or LuaJIT. FWIW, LuaJIT is Lua 5.1 compatible and implements part of Lua 5.2 (plus some additions that are not part of the standard). There's no plans at the moment to implement Lua 5.3.
Lastly, I coded a bitwise module for Lua in plain Lua. Probably it will be terribly slow, but perhaps may be useful https://gist.github.com/dpino/73c08ccfe6ca074fac36
Comment From: antirez
@dpino we don't have good reasons to upgrade to 5.3 since it breaks existing Lua scripts and for Redis most features of 5.3 are not critical to have... So we have to find a solution within our current implementation :-) Thanks.
Comment From: beaters
Back up to the first cash of Sent from my BlackBerry 10 smartphone. From: Salvatore SanfilippoSent: 2015年11月2日星期一 23:57To: antirez/redisReply To: antirez/redisSubject: Re: [redis] Bitwise logic operations on large numbers(up to 53 bits) (#2843)The version of Lua we use is kinda terrible and had no concept of integer type. Fortunately if I remember correctly now Lua is going to have proper integers. I hope that after Lua and Javascript, nobody will design again a language with just floats. Btw, even with floats, 53 bits is what we should get, so there is some kind of other problem probably. I'll investigate and fix it. Thanks.
—Reply to this email directly or view it on GitHub.
Comment From: daurnimator
@dpino we don't have good reasons to upgrade to 5.3 since it breaks existing Lua scripts and for Redis most features of 5.3 are not critical to have... So we have to find a solution within our current implementation :-) Thanks.
Do you have much evidence for this? If you turn on the LUA_COMPAT_5_1 flag when compiling lua 5.3 there is very little that doesn't work in a backwards incompatible manner.
The issues would be around:
- Binary (i.e. C) modules; which are disabled in redis anyway
- Any use of setfenv (IMO redis lua scripts shouldn't be using this anyway)
Comment From: beaters
发送自我的 BlackBerry 10 智能手机。 发件人: 刘希岗已发送: 2015年11月11日星期三 18:50收件人: Salvatore Sanfilippo; antirez/redis主题: Re: [redis] Bitwise logic operations on large numbers(up to 53 bits) (#2843) Back up to the first cash of Sent from my BlackBerry 10 smartphone. From: Salvatore SanfilippoSent: 2015年11月2日星期一 23:57To: antirez/redisReply To: antirez/redisSubject: Re: [redis] Bitwise logic operations on large numbers(up to 53 bits) (#2843)The version of Lua we use is kinda terrible and had no concept of integer type. Fortunately if I remember correctly now Lua is going to have proper integers. I hope that after Lua and Javascript, nobody will design again a language with just floats. Btw, even with floats, 53 bits is what we should get, so there is some kind of other problem probably. I'll investigate and fix it. Thanks.
—Reply to this email directly or view it on GitHub.
So with this kind of problems,i think you at least should learn something important in your daily work.Btw,you must keep the thought that we can't be afraid of the error,on the contrary,they are our best friends on our road to success in our mind. Your sincenly Liu
Comment From: fcolista
Still no plan for lua5.3?