math.lua
1 local M = {} 2 3 M.clamp = function(x, min, max) 4 return x < min and min or (x > max and max or x) 5 end 6 7 M.round = function(x, increment) 8 if increment then 9 return M.round(x / increment) * increment 10 end 11 return x >= 0 and math.floor(x + 0.5) or math.ceil(x - 0.5) 12 end 13 14 return M