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.

39 lines
1.3 KiB

import math
from src.main.py.logarithmic_and_expo_and_root_calculations import potentiate
from src.main.py.primitive_calculations import *
def pi_approx_leibniz(precision):
if precision < 0:
return -1
result = 0
for i in range(precision):
num = potentiate(-1, i)
denom = add(1, multiply(2,i))
result = add(result, divide(num, denom))
return multiply(result, 4)
def rad2deg(radNumber):
return (radNumber * 180) / math.pi
def sin_approx_bhaskara(radNumber):
while(radNumber > 2 * math.pi):
radNumber -= 2 * math.pi
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
if math.pi < radNumber < 2 * math.pi:
radNumber = subract(math.pi, radNumber)
shallFlipTheResult = 1
num = multiply(16, radNumber)
num = multiply(num, subract(radNumber, math.pi))
denomFrag1 = multiply(5, math.pow(math.pi, 2))
denomFrag2 = subract(radNumber, math.pi)
denomFrag2 = multiply(denomFrag2, radNumber)
denomFrag2 = multiply(denomFrag2, 4)
sinResult = divide(num, subract(denomFrag2, denomFrag1))
if(shallFlipTheResult == 1):
return multiply(sinResult, -1)
return sinResult