[algo] Add sign() function
This commit is contained in:
parent
08ac115ea2
commit
34221bf850
6
algo.lua
6
algo.lua
|
@ -18,6 +18,12 @@ local algo = {}
|
||||||
-- @treturn number clamped value.
|
-- @treturn number clamped value.
|
||||||
function algo.clamp(x, a, b) return min(max(x, a), b) end
|
function algo.clamp(x, a, b) return min(max(x, a), b) end
|
||||||
|
|
||||||
|
--- Sign function.
|
||||||
|
--
|
||||||
|
-- @number x value whose sign should be returned.
|
||||||
|
-- @treturn number sign of x, -1 if negative, 1 if positive, 0 otherwise.
|
||||||
|
function algo.sign(x) return x > 0 and 1 or x < 0 and -1 or 0 end
|
||||||
|
|
||||||
--- Fast remove from array.
|
--- Fast remove from array.
|
||||||
--
|
--
|
||||||
-- Replace 'array[i]' with last array's element and
|
-- Replace 'array[i]' with last array's element and
|
||||||
|
|
Loading…
Reference in New Issue