add utils.sign
This commit is contained in:
parent
f11cea9588
commit
919900fea2
@ -211,4 +211,18 @@ function utils.refract(i, n, ior)
|
||||
return vec3()
|
||||
end
|
||||
|
||||
--- Get the sign of a number
|
||||
-- returns 1 for positive values, -1 for negative and 0 for zero.
|
||||
-- @param value
|
||||
-- @return number
|
||||
function utils.sign(n)
|
||||
if n > 0 then
|
||||
return 1
|
||||
elseif n < 0 then
|
||||
return -1
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
return utils
|
||||
|
@ -44,6 +44,12 @@ describe("utils:", function()
|
||||
v = utils.round(1.3242525)
|
||||
assert.is_true(tolerance(v, 1))
|
||||
end)
|
||||
|
||||
it("checks sign", function()
|
||||
assert.is.equal(utils.sign(-9), -1)
|
||||
assert.is.equal(utils.sign(0), 0)
|
||||
assert.is.equal(utils.sign(12), 1)
|
||||
end)
|
||||
end)
|
||||
|
||||
--[[
|
||||
|
Loading…
x
Reference in New Issue
Block a user