From 730b0f5c5c39fabadc78ab1d1f9331d6256d1533 Mon Sep 17 00:00:00 2001 From: hung Date: Fri, 1 May 2020 15:17:14 +0700 Subject: [PATCH] gears.math: add the sign function --- lib/gears/math.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/gears/math.lua b/lib/gears/math.lua index 61c19d004..db295f673 100644 --- a/lib/gears/math.lua +++ b/lib/gears/math.lua @@ -76,5 +76,19 @@ function gmath.round(x) return math.floor(x + 0.5) 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