Posted By

leazen on 06/30/06


Tagged

pi generator


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

anayhk


Pi


 / Published in: Python
 

  1. def pi():
  2. # Compute digits of Pi.
  3. # Algorithm due to LGLT Meertens.
  4. k, a, b, a1, b1 = 2, 4, 1, 12, 4
  5. while 1:
  6. p, q, k = k*k, 2*k+1, k+1
  7. a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
  8. d, d1 = a//b, a1//b1
  9. while d == d1:
  10. yield d
  11. a, a1 = 10*(a%b), 10*(a1%b1)
  12. d, d1 = a//b, a1//b1

Report this snippet  

You need to login to post a comment.