support negative values passed to frexp

This commit is contained in:
airstruck 2015-09-08 05:01:11 -04:00
parent 5081314be6
commit b50194bebc

View File

@ -2,10 +2,12 @@ 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)
return x / 2 ^ e, e
if x == 0 then return 0, 0 end
local e = math.floor(math.log(math.abs(x)) / log2 + 1)
return x / 2 ^ e, e
end
function utils.clamp(v, min, max)