diff --git a/src/main/py/trigonometry.py b/src/main/py/trigonometry.py index ac7fbce..d679dea 100644 --- a/src/main/py/trigonometry.py +++ b/src/main/py/trigonometry.py @@ -1,3 +1,13 @@ import math +from src.main.py.logarithmic_and_expo_and_root_calculations import potentiate + +def pi_approx_leibniz(precision): + result = 0 + for i in range(precision): + num = potentiate(-1, i) + denom = 2*i + 1 + result += num/denom + return result * 4 + def rad2deg(radNumber): return (radNumber * 180) / math.pi \ No newline at end of file diff --git a/src/test/py/test_trigonometry.py b/src/test/py/test_trigonometry.py index fcd919b..f4b7442 100644 --- a/src/test/py/test_trigonometry.py +++ b/src/test/py/test_trigonometry.py @@ -9,6 +9,12 @@ class MyTestCase(unittest.TestCase): def tearDown(self): pass + def test_pi_precision_1000000_should_be_3_point_141592(self): + delta = pi_approx_leibniz(1000000) - 3.141592 + if delta < 0: + delta *= -1 + self.assertLess(delta, 0.01) + def test_rad_2_to_deg_should_be_114_point_59(self): delta = rad2deg(2) - 114.59 if delta < 0: