diff --git a/src/main/py/trigonometry.py b/src/main/py/trigonometry.py index 282137b..1043118 100644 --- a/src/main/py/trigonometry.py +++ b/src/main/py/trigonometry.py @@ -15,6 +15,13 @@ def rad2deg(radNumber): return (radNumber * 180) / math.pi def sin_approx_bhaskara(radNumber): + + shallFlipTheResult = 0 + if math.pi < radNumber < 2 * math.pi: + radNumber -= math.pi + shallFlipTheResult = 1 + + num = multiply(16, radNumber) num = multiply(num, subract(radNumber, math.pi)) @@ -23,4 +30,8 @@ def sin_approx_bhaskara(radNumber): denomFrag2 = multiply(denomFrag2, radNumber) denomFrag2 = multiply(denomFrag2, 4) - return divide(num, subract(denomFrag2, denomFrag1)) \ No newline at end of file + sinResult = divide(num, subract(denomFrag2, denomFrag1)) + + if(shallFlipTheResult == 1): + return sinResult * -1 + return sinResult \ No newline at end of file diff --git a/src/test/py/test_trigonometry.py b/src/test/py/test_trigonometry.py index 8297175..9c1829c 100644 --- a/src/test/py/test_trigonometry.py +++ b/src/test/py/test_trigonometry.py @@ -44,6 +44,9 @@ class MyTestCase(unittest.TestCase): delta = sin_approx_bhaskara(0.25*math.pi) - 0.707 self.assertLess(delta, 0.01) + def test_sin_1point5_pi_should_be_negative_1(self): + self.assertEqual(sin_approx_bhaskara(1.5*math.pi), -1) + if __name__ == '__main__': unittest.main()