mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 07:13:45 +01:00
Add math.sign
This commit is contained in:
parent
e048fb3b03
commit
83c5c87390
8
math.lua
8
math.lua
@ -8,6 +8,7 @@ local inf = math.huge
|
||||
local _ENV = {}
|
||||
setfenv(1, _ENV)
|
||||
|
||||
-- TODO might be too invasive
|
||||
-- Make random random
|
||||
math.randomseed(minetest and minetest.get_us_time() or os.time() + os.clock())
|
||||
for _ = 1, 100 do math.random() end
|
||||
@ -15,6 +16,13 @@ for _ = 1, 100 do math.random() end
|
||||
negative_nan = 0/0
|
||||
positive_nan = negative_nan ^ 1
|
||||
|
||||
function sign(number)
|
||||
if number ~= number then return number end -- nan
|
||||
if number == 0 then return 0 end
|
||||
if number < 0 then return -1 end
|
||||
if number > 0 then return 1 end
|
||||
end
|
||||
|
||||
function round(number, steps)
|
||||
steps = steps or 1
|
||||
return math_floor(number * steps + 0.5) / steps
|
||||
|
Loading…
Reference in New Issue
Block a user