Advertisement
Guest User

Math Module

a guest
Jul 2nd, 2012
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. ------------------
  2. --MATH FUNCTIONS--
  3. ------------------
  4.  
  5. function math.root(a,b)
  6.     return math.pow(a,(1/b))
  7. end
  8. function math.logx(a,b)
  9.     return math.log10(a)/math.log10(b)
  10. end
  11. function math.digits(a,b)
  12.     b = b or 10
  13.     return math.floor(math.logx(a,b))
  14. end
  15. function math.summation(a,b)
  16.     if a == 1 then return b*(b+1)/2 end
  17.     local r = 0
  18.     for i = a, b do
  19.         r = r+i
  20.     end
  21.     return r
  22. end
  23. function math.factorial(x)
  24.     if x == 1 or x == 0 then return 1 end
  25.     local r = 1
  26.     for i=2, x do
  27.         r = r * i
  28.     end
  29.     return r
  30. end
  31. function math.powerset(s,n)
  32.     n = n or 1
  33.     if n>#s then
  34.         return {{}}
  35.     end
  36.     local r = math.powerset(s,n+1)
  37.     for i=1,#r do
  38.         r[#r+1] = {s[n], table.unpack(r[i])}
  39.     end
  40.     return r
  41. end
  42.  
  43. function math.normalizerad(r)
  44.     if r>math.pi then
  45.         r = -math.pi+r%math.pi
  46.     elseif r<-math.pi then
  47.         r = math.pi-(math.pi-r%math.pi)
  48.     end
  49.     return r
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement