I am trying to calculate pi with arbitrary precision in Python using one of the Ramanujan formulas: http://en.wikipedia.org/wiki/Approximations_of_%CF%80#20th_century . This basically requires a large number of factorials and division of floating numbers with high accuracy.
Here is my code: http://pastie.org/private/pa6ijmoowiwiw4xwiqmq
I get an error somewhere around the fifteenth digit pi (3.1415926535897930, and that should be 3.1415926535897932). Can you give some advice why this is happening? I use the decimal type, and the docs say that it allows arbitrary values ββof floating point numbers and integers.
PS: This is homework, so I canβt use a different formula. PSS: I am using python 2.7
Thanks:)
source share