Skip to content

Instantly share code, notes, and snippets.

@honux77
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save honux77/409fdecf1cbec4264693 to your computer and use it in GitHub Desktop.

Select an option

Save honux77/409fdecf1cbec4264693 to your computer and use it in GitHub Desktop.
math sine implementation
import math
def fact(x):
if x == 1:
return 1
else:
return x * fact(x-1);
def mysin(x):
return x - math.pow(x,3)/fact(3) + pow(x,5)/fact(5) - pow(x,7)/fact(7) \
+ math.pow(x,9)/fact(9)
print mysin(3.14/2), math.sin(3.14/2)
print mysin(3.14/4), math.sin(3.14/4), 1/math.sqrt(2)
@honux77
Copy link
Copy Markdown
Author

honux77 commented Feb 4, 2015

12:03 $ python math_test.py
1.00000320587 0.999999682932
0.706825182846 0.706825181105 0.707106781187

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment