mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add math.lua, move all math related helpers in to it
This commit is contained in:
25
frontend/math.lua
Normal file
25
frontend/math.lua
Normal 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user