Skip to content
This repository was archived by the owner on Aug 4, 2024. It is now read-only.

faster round_value #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions classes/cLib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ function cLib.least_common(t)
end

---------------------------------------------------------------------------------------------------
-- [Static] Round value (from http://lua-users.org/wiki/SimpleRound)
-- [Static] Round value
-- @param num (number)

function cLib.round_value(num)
if num >= 0 then return math.floor(num+.5)
else return math.ceil(num-.5) end
local frac = num % 1
return frac < 0.5 and num - frac or num + 1 - frac
end

---------------------------------------------------------------------------------------------------
Expand Down