fix math.modf in case value equal 0 or ±Inf

This commit is contained in:
Pinya
2018-02-15 21:18:51 +03:00
parent cee03dfde1
commit 74011a85c2
+9
View File
@@ -46,11 +46,20 @@ function select(n, ...)
return unpack(args)
end
local huge = math.huge
function math.modf(i)
i = type(i) ~= "number" and tonumber(i) or i
if type(i) ~= "number" then
error(format("bad argument #1 to 'modf' (number expected, got %s)", i and type(i) or "no value"), 2)
end
if i == 0 then
return i, i
elseif abs(i) == huge then
return i, i > 0 and 0 or -0
end
local int = i >= 0 and floor(i) or ceil(i)
return int, i - int