关于luajit 64bit 位运算的问题

508 views
Skip to first unread message

coding...@gmail.com

unread,
Jun 8, 2016, 6:14:41 AM6/8/16
to openresty
看到luajit2.1已经支持64bit位运算了,然后升级了下luajit,貌似并不管用呢,求解?

或者有其他方法来支持64bit的位运算么?

DeJiang Zhu

unread,
Jun 10, 2016, 9:34:53 AM6/10/16
to open...@googlegroups.com

Hello

据我所知,还没看到 64位位运算的支持,从这个文档看也只有 32 位的



--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html

Yichun Zhang (agentzh)

unread,
Jun 22, 2016, 1:32:48 AM6/22/16
to openresty
Hello!
可以。通过 int64_t 或者 uint64_t 类型的 FFI cdata 类型。比如:

$ luajit -e 'local bit = require "bit" print(bit.lshift(0xffffffffffLL, 1))'
2199023255550LL

Regards,
-agentzh

ErenNo1

unread,
Jun 22, 2016, 11:26:19 PM6/22/16
to open...@googlegroups.com
看起来不错,感谢回复!

由于64bit的数据是通过cjson解析出来的,看起来是避免不了转换为double的过程(索性业务上这个整数最大不会超过2^53),所以我的解决方案如下:

uint64-----cjson decode----> lua double ------C module----> C bitop -----> lua double


Chen Jian

unread,
Jul 25, 2016, 7:54:10 PM7/25/16
to openresty
为啥抛出这个错误?
luajit -e 'local bit = require "bit" print(bit.lshift(0xffffffffffLL, 1))'
luajit: (command line):1: bad argument #1 to 'lshift' (number expected, got cdata)
stack traceback:
[C]: in function 'lshift'
(command line):1: in main chunk
[C]: at 0x0100002150

在 2016年6月22日星期三 UTC+8下午1:32:48,agentzh写道:

YuanSheng Wang

unread,
Jul 26, 2016, 8:51:38 AM7/26/16
to open...@googlegroups.com
2016-07-26 7:54 GMT+08:00 Chen Jian <jianch...@gmail.com>:
为啥抛出这个错误?
luajit -e 'local bit = require "bit" print(bit.lshift(0xffffffffffLL, 1))'
luajit: (command line):1: bad argument #1 to 'lshift' (number expected, got cdata)
stack traceback:
[C]: in function 'lshift'
(command line):1: in main chunk
[C]: at 0x0100002150


更新你的 luajit 版本,应该是你版本太低不支持 64bit 。

➜  ~ luajit -v
LuaJIT 2.1.0-beta2 -- Copyright (C) 2005-2016 Mike Pall. http://luajit.org/

 
在 2016年6月22日星期三 UTC+8下午1:32:48,agentzh写道:
Hello!

On Wed, Jun 8, 2016 at 3:14 AM,  codingforfan wrote:
> 看到luajit2.1已经支持64bit位运算了,然后升级了下luajit,貌似并不管用呢,求解?
>
> http://luajit.org/sponsors.html#sponsorship_bit64
>
> 或者有其他方法来支持64bit的位运算么?
>

可以。通过 int64_t 或者 uint64_t 类型的 FFI cdata 类型。比如:

    $ luajit -e 'local bit = require "bit" print(bit.lshift(0xffffffffffLL, 1))'
    2199023255550LL

Regards,
-agentzh

--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html



--

YuanSheng Wang
---------------------------------------
OpenResty lover ^_^
Reply all
Reply to author
Forward
0 new messages