Edit the documentation or categories for this module.
-- MathUtil
local p = {}
function p.sign(v)
if v == 0 then return 0 end
return (v > 0 and 1) or -1
end
function p.printWithSign(v)
return (v > 0 and ('+%s'):format(v)) or v
end
function p.roundnum(v, bracket)
bracket = bracket or 1
return math.floor(v/bracket + p.sign(v) * 0.5) * bracket
end
function p.mod(a, b)
return a - math.floor(a/b)*b
end
function p.sum(tbl)
local total = 0
for _, v in pairs(tbl) do
total = total + v
end
return total
end
return p