Commit 6cca8e5a authored by François Perrad's avatar François Perrad
Browse files

fix pack float with Lua 5.3

bad argument #5 to 'char' (number has no integer representation)
parent 3dc57aa3
Revision history for lua-MessagePack
0.3.6
fix pack float with Lua 5.3
0.3.5 Sat Oct 22 22:30:00 2016
fix float/integer detection
refactor doc with Markdown and MkDocs
......
......@@ -413,7 +413,7 @@ packers['float'] = function (buffer, n)
sign, 0x00, 0x00, 0x00)
else
expo = expo + 0x7E
mant = (mant * 2.0 - 1.0) * ldexp(0.5, 24)
mant = floor((mant * 2.0 - 1.0) * ldexp(0.5, 24))
buffer[#buffer+1] = char(0xCA,
sign + floor(expo / 0x2),
(expo % 0x2) * 0x80 + floor(mant / 0x10000),
......@@ -445,7 +445,7 @@ packers['double'] = function (buffer, n)
sign, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
else
expo = expo + 0x3FE
mant = (mant * 2.0 - 1.0) * ldexp(0.5, 53)
mant = floor((mant * 2.0 - 1.0) * ldexp(0.5, 53))
buffer[#buffer+1] = char(0xCB,
sign + floor(expo / 0x10),
(expo % 0x10) * 0x10 + floor(mant / 0x1000000000000),
......
......@@ -2,7 +2,7 @@
require 'Test.More'
plan(41)
plan(42)
local mp = require 'MessagePack'
......@@ -48,6 +48,10 @@ mp.set_array'always_as_map'
is( mp.pack(t):byte(), 0x80, "empty table as map" )
mp.set_number'float'
lives_ok( function ()
mp.pack(1.5000001)
end,
"float 1.5000001" )
is( mp.pack(3.402824e+38), mp.pack(1.0/0.0), "float 3.402824e+38")
is( mp.pack(7e42), mp.pack(1.0/0.0), "inf (downcast double -> float)")
is( mp.pack(-7e42), mp.pack(-1.0/0.0), "-inf (downcast double -> float)")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment