Simon Cooke
2014-10-16 15:24:33 UTC
In the following test, arithmetic with cdata<double &> forces
conversion to 64-bit integers:
--------------------
local ffi = require'ffi'
local v = ffi.new('double[1]',2.5)
local x = ffi.cast('double&',v)
print(x, tonumber(x))
print(x+.25, tonumber(x)+.25)
print(x-.25, tonumber(x)-.25)
print(x*.25, tonumber(x)*.25)
print(x+x, tonumber(x)+tonumber(x))
--------------------
cdata<double &>: 0x01fbb9f8 2.5
2LL 2.75
2LL 2.25
0LL 0.625
4LL 5
(Tested using both LuaJIT 2.0.3 and the latest 2.0 HEAD, on 64 bit
GCC-4.9 and MSVC-12)
conversion to 64-bit integers:
--------------------
local ffi = require'ffi'
local v = ffi.new('double[1]',2.5)
local x = ffi.cast('double&',v)
print(x, tonumber(x))
print(x+.25, tonumber(x)+.25)
print(x-.25, tonumber(x)-.25)
print(x*.25, tonumber(x)*.25)
print(x+x, tonumber(x)+tonumber(x))
--------------------
cdata<double &>: 0x01fbb9f8 2.5
2LL 2.75
2LL 2.25
0LL 0.625
4LL 5
(Tested using both LuaJIT 2.0.3 and the latest 2.0 HEAD, on 64 bit
GCC-4.9 and MSVC-12)
From the manual I would expect conversion to 'number'. Is this a bug?
Simon