You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.3 KiB

  1. import math
  2. from src.main.py.logarithmic_and_expo_and_root_calculations import potentiate
  3. from src.main.py.primitive_calculations import *
  4. def pi_approx_leibniz(precision):
  5. if precision < 0:
  6. return -1
  7. result = 0
  8. for i in range(precision):
  9. num = potentiate(-1, i)
  10. denom = add(1, multiply(2,i))
  11. result = add(result, divide(num, denom))
  12. return multiply(result, 4)
  13. def rad2deg(radNumber):
  14. return (radNumber * 180) / math.pi
  15. def sin_approx_bhaskara(radNumber):
  16. while(radNumber > 2 * math.pi):
  17. radNumber -= 2 * math.pi
  18. shallFlipTheResult = 0 #the bhaskara function can only be used between zero and pi. For the rest of the sin period I simply mirrored the first arch of the curve to match the actual sine wave
  19. if math.pi < radNumber < 2 * math.pi:
  20. radNumber = subract(math.pi, radNumber)
  21. shallFlipTheResult = 1
  22. num = multiply(16, radNumber)
  23. num = multiply(num, subract(radNumber, math.pi))
  24. denomFrag1 = multiply(5, math.pow(math.pi, 2))
  25. denomFrag2 = subract(radNumber, math.pi)
  26. denomFrag2 = multiply(denomFrag2, radNumber)
  27. denomFrag2 = multiply(denomFrag2, 4)
  28. sinResult = divide(num, subract(denomFrag2, denomFrag1))
  29. if(shallFlipTheResult == 1):
  30. return multiply(sinResult, -1)
  31. return sinResult