Merge pull request #7 from airstruck/patch-1
support negative values passed to frexp
This commit is contained in:
commit
2ffad16f80
@ -2,9 +2,11 @@ local utils = {}
|
||||
|
||||
-- reimplementation of math.frexp, due to its removal from Lua 5.3 :(
|
||||
-- courtesy of airstruck
|
||||
local log2 = math.log(2)
|
||||
|
||||
local frexp = math.frexp or function(x)
|
||||
if x == 0 then return 0, 0 end
|
||||
local e = math.floor(math.log(x) / math.log(2) + 1)
|
||||
local e = math.floor(math.log(math.abs(x)) / log2 + 1)
|
||||
return x / 2 ^ e, e
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user