gears.math: add the sign function

This commit is contained in:
hung 2020-05-01 15:17:14 +07:00
parent 29f6387def
commit 730b0f5c5c
1 changed files with 14 additions and 0 deletions

View File

@ -76,5 +76,19 @@ function gmath.round(x)
return math.floor(x + 0.5) return math.floor(x + 0.5)
end end
--- Return the sign of the number x
-- return 1 if x is positive, -1 if negative and 0 if x is 0
-- @tparam number x
-- @treturn integer
-- @staticfct gears.math.sign
function gmath.sign(x)
if x > 0 then
return 1
elseif x < 0 then
return -1
else
return 0
end
end
return gmath return gmath