mirror of
https://github.com/kepler155c/opus
synced 2025-02-04 11:19:11 +00:00
Merge pull request #4 from sorucoder/develop-1.8
Added util.signum, util.clamp, and fixed util.round
This commit is contained in:
commit
68217cfd52
@ -109,10 +109,30 @@ function Util.checkMinecraftVersion(minVersion)
|
|||||||
return convert(version) >= convert(tostring(minVersion))
|
return convert(version) >= convert(tostring(minVersion))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Util.signum(num)
|
||||||
|
if num > 0 then
|
||||||
|
return 1
|
||||||
|
elseif num < 0 then
|
||||||
|
return -1
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Util.clamp(lo, n, hi)
|
||||||
|
if num <= lo then
|
||||||
|
return lo
|
||||||
|
elseif num >= hi then
|
||||||
|
return hi
|
||||||
|
else
|
||||||
|
return n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- http://lua-users.org/wiki/SimpleRound
|
-- http://lua-users.org/wiki/SimpleRound
|
||||||
function Util.round(num, idp)
|
function Util.round(num, idp)
|
||||||
local mult = 10^(idp or 0)
|
local mult = 10^(idp or 0)
|
||||||
return math.floor(num * mult + 0.5) / mult
|
return util.signum(num) * math.floor(math.abs(num) * mult + 0.5) / mult
|
||||||
end
|
end
|
||||||
|
|
||||||
function Util.random(max, min)
|
function Util.random(max, min)
|
||||||
|
Loading…
Reference in New Issue
Block a user