add math.lua, move all math related helpers in to it

This commit is contained in:
Qingping Hou
2013-02-19 11:57:14 +08:00
parent 79b3ee91c7
commit f3452234ea
5 changed files with 33 additions and 36 deletions

25
frontend/math.lua Normal file
View File

@@ -0,0 +1,25 @@
--[[
Simple math helper function
]]--
function math.roundAwayFromZero(num)
if num > 0 then
return math.ceil(num)
else
return math.floor(num)
end
end
function math.round(num)
return math.floor(num + 0.5)
end
function math.oddEven(number)
if number % 2 == 1 then
return "odd"
else
return "even"
end
end