mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
cleanup: expand tab to 4 spaces
This commit is contained in:
@@ -5,42 +5,42 @@ Simple math helper function
|
||||
local Math = {}
|
||||
|
||||
function Math.roundAwayFromZero(num)
|
||||
if num > 0 then
|
||||
return math.ceil(num)
|
||||
else
|
||||
return math.floor(num)
|
||||
end
|
||||
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)
|
||||
return math.floor(num + 0.5)
|
||||
end
|
||||
|
||||
function Math.oddEven(number)
|
||||
if number % 2 == 1 then
|
||||
return "odd"
|
||||
else
|
||||
return "even"
|
||||
end
|
||||
if number % 2 == 1 then
|
||||
return "odd"
|
||||
else
|
||||
return "even"
|
||||
end
|
||||
end
|
||||
|
||||
local function tmin_max(tab, func, op)
|
||||
if #tab == 0 then return nil, nil end
|
||||
local index, value = 1, tab[1]
|
||||
if #tab == 0 then return nil, nil end
|
||||
local index, value = 1, tab[1]
|
||||
for i = 2, #tab do
|
||||
if func then
|
||||
if func(value, tab[i]) then
|
||||
index, value = i, tab[i]
|
||||
end
|
||||
elseif op == "min" then
|
||||
if value > tab[i] then
|
||||
index, value = i, tab[i]
|
||||
end
|
||||
elseif op == "max" then
|
||||
if value < tab[i] then
|
||||
index, value = i, tab[i]
|
||||
end
|
||||
end
|
||||
if func then
|
||||
if func(value, tab[i]) then
|
||||
index, value = i, tab[i]
|
||||
end
|
||||
elseif op == "min" then
|
||||
if value > tab[i] then
|
||||
index, value = i, tab[i]
|
||||
end
|
||||
elseif op == "max" then
|
||||
if value < tab[i] then
|
||||
index, value = i, tab[i]
|
||||
end
|
||||
end
|
||||
end
|
||||
return index, value
|
||||
end
|
||||
@@ -50,7 +50,7 @@ Return the minimum element of a table.
|
||||
The optional argument func specifies a one-argument ordering function.
|
||||
]]--
|
||||
function Math.tmin(tab, func)
|
||||
return tmin_max(tab, func, "min")
|
||||
return tmin_max(tab, func, "min")
|
||||
end
|
||||
|
||||
--[[
|
||||
@@ -58,7 +58,7 @@ Return the maximum element of a table.
|
||||
The optional argument func specifies a one-argument ordering function.
|
||||
]]--
|
||||
function Math.tmax(tab, func)
|
||||
return tmin_max(tab, func, "max")
|
||||
return tmin_max(tab, func, "max")
|
||||
end
|
||||
|
||||
return Math
|
||||
|
||||
Reference in New Issue
Block a user