Advertisement
YuRaNnNzZZ

GLua math functions for regular Lua

Feb 20th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.52 KB | None | 0 0
  1. -- This is some of math functions that available in GLua but missing in vanilla Lua.
  2.  
  3. math.Clamp = math.Clamp or function(val, lower, upper)
  4.     assert(val and lower and upper, "not very useful error message here")
  5.     if lower > upper then lower, upper = upper, lower end -- swap if boundaries supplied the wrong way
  6.     return math.max(lower, math.min(upper, val))
  7. end
  8.  
  9. math.Round = math.Round or function(num, numDecimalPlaces)
  10.     local mult = 10^(numDecimalPlaces or 0)
  11.     return math.floor(num * mult + 0.5) / mult
  12. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement