Bluon: Write out-of-bounds ints as floats

This commit is contained in:
Lars Mueller 2022-06-27 22:14:42 +02:00
parent cc0a56dd7a
commit 898db2c278

@ -1,6 +1,6 @@
-- Localize globals -- Localize globals
local assert, error, ipairs, math_floor, math_huge, modlib, next, pairs, setmetatable, string, table_insert, type, unpack local assert, error, ipairs, math_floor, math_abs, math_huge, modlib, next, pairs, setmetatable, string, table_insert, type, unpack
= assert, error, ipairs, math.floor, math.huge, modlib, next, pairs, setmetatable, string, table.insert, type, unpack = assert, error, ipairs, math.floor, math.abs, math.huge, modlib, next, pairs, setmetatable, string, table.insert, type, unpack
-- Set environment -- Set environment
local _ENV = {} local _ENV = {}
@ -203,7 +203,7 @@ function write(self, value, stream)
stream:write(constant_nan) stream:write(constant_nan)
return return
end end
if value % 1 == 0 then if value % 1 == 0 and math_abs(value) < 2^64 then
uint_with_type(value > 0 and type_ranges.number_constant or type_ranges.number_negative, value > 0 and value or -value) uint_with_type(value > 0 and type_ranges.number_constant or type_ranges.number_negative, value > 0 and value or -value)
return return
end end
@ -332,4 +332,4 @@ function read(self, stream)
end end
-- Export environment -- Export environment
return _ENV return _ENV