[checked revision] | [checked revision] |
(Syncing content across wikis, if something seems broken as a result let me know) |
m (Protected "Module:MathUtil": Syncing content across wikis, if something seems broken as a result let me know ([Edit=Allow only administrators] (indefinite))) |
(No difference)
|
Revision as of 12:19, 15 February 2019
To edit the documentation or categories for this module, click here.
-- 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