mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-25 16:53:46 +01:00
Fix binary.write_float
This commit is contained in:
parent
c823ca9533
commit
c0b2957c67
@ -104,10 +104,14 @@ function write_float(write_byte, number, on_write, double)
|
|||||||
end
|
end
|
||||||
local mantissa, exponent = math_frexp(number)
|
local mantissa, exponent = math_frexp(number)
|
||||||
exponent = exponent + 127
|
exponent = exponent + 127
|
||||||
|
if number == 0 then exponent = 0 end -- zero must be written as a subnormal number
|
||||||
if exponent > 1 then
|
if exponent > 1 then
|
||||||
-- TODO ensure this deals properly with subnormal numbers
|
-- TODO ensure this deals properly with subnormal numbers
|
||||||
mantissa = mantissa * 2 - 1
|
mantissa = mantissa * 2 - 1
|
||||||
exponent = exponent - 1
|
exponent = exponent - 1
|
||||||
|
elseif exponent < 0 then -- number is currently sub-subnormal, subnormalize
|
||||||
|
mantissa = mantissa * 2^(exponent-1)
|
||||||
|
exponent = 0
|
||||||
end
|
end
|
||||||
local sign_byte = sign + math_floor(exponent / 2)
|
local sign_byte = sign + math_floor(exponent / 2)
|
||||||
if double == nil then
|
if double == nil then
|
||||||
|
Loading…
Reference in New Issue
Block a user