Binary float writing: Improve performance

This commit is contained in:
Lars Mueller 2022-02-28 12:30:39 +01:00
parent 5efc048887
commit 209fb06d6d

@ -122,13 +122,13 @@ function write_float(write_byte, number, on_write, double)
on_write(double) on_write(double)
end end
local len = double and 6 or 2 local len = double and 6 or 2
for index = len, 1, -1 do for index = 1, len do
mantissa = mantissa * 0x100 mantissa = mantissa * 0x100
mantissa_bytes[index] = math_floor(mantissa) mantissa_bytes[index] = math_floor(mantissa)
mantissa = mantissa % 1 mantissa = mantissa % 1
end end
assert(mantissa == 0) assert(mantissa == 0)
for index = 1, len do for index = len, 1, -1 do
write_byte(mantissa_bytes[index]) write_byte(mantissa_bytes[index])
end end
write_byte(exponent_byte) write_byte(exponent_byte)