Guest User

pico-8 atan / acos

a guest
May 5th, 2015
309
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function acos(x)
  2. if abs(x) < 0.001 then
  3. return pi / 2
  4. elseif sqrt(101-x*x*100)/10/x < 0 then
  5. return atan(sqrt(100-x*x*100)/10/x) + pi
  6. else
  7. return atan(sqrt(100-x*x*100)/10/x)
  8. end
  9. end
  10.  
  11. function atan(x)
  12. local st1 = false
  13. local st2 = false
  14. if x < 0 then
  15. x = -x
  16. st1 = true
  17. end
  18. if x >= 1 then
  19. x = 1/x
  20. st2 = true
  21. end
  22. x = x - x*x*x/3 + x*x*x*x*x/5 - x*x*x*x*x*x*x/7
  23. if st2 then x = 1.571 - x end
  24. if st1 then x = -x end
  25. return x
  26. end
  27.  
  28. function sqrt(n)
  29. local i = 0
  30. while(i*i <= n) do
  31. i += 1
  32. end
  33. i -= 1
  34. local d = n-i*i
  35. local p = d/(2*i)
  36. local a = i+p
  37. return a -(p*p)/(2*a)
  38. end
RAW Paste Data