mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-26 09:13:53 +01:00
Fix math.fround
This commit is contained in:
parent
f5dd65d772
commit
859d617138
5
math.lua
5
math.lua
@ -61,12 +61,11 @@ function fround(number)
|
|||||||
number = -number
|
number = -number
|
||||||
end
|
end
|
||||||
local exp = math.floor(math.log(number, 2))
|
local exp = math.floor(math.log(number, 2))
|
||||||
local powexp = 2 ^ math.max(-126, math.min(number, 127))
|
local powexp = 2 ^ math.max(-126, math.min(exp, 127))
|
||||||
local leading = exp < -127 and 0 or 1
|
local leading = exp < -127 and 0 or 1
|
||||||
local mantissa = math.floor((leading - number / powexp) * 0x800000 + 0.5)
|
local mantissa = math.floor((leading - number / powexp) * 0x800000 + 0.5)
|
||||||
if mantissa <= -0x800000 then
|
if mantissa <= -0x800000 then
|
||||||
return sign * math.huge
|
return sign * math.huge
|
||||||
end
|
end
|
||||||
mantissa = mantissa / 0x800000
|
return sign * powexp * (leading - mantissa / 0x800000)
|
||||||
return sign * powexp * (leading - mantissa), mantissa
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user