Created
August 13, 2009 05:33
-
-
Save jtauber/167009 to your computer and use it in GitHub Desktop.
Pi in Hex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Implementation of Simon Plouffe's formula for Pi in Hex | |
# | |
# James Tauber 2007-03-14 | |
# http://jtauber.com/blog/2007/03/14/generating_the_hex_digits_of_pi/ | |
def pi(): | |
N = 0 | |
n, d = 0, 1 | |
while True: | |
xn = (120*N**2 + 151*N + 47) | |
xd = (512*N**4 + 1024*N**3 + 712*N**2 + 194*N + 15) | |
n = ((16 * n * xd) + (xn * d)) % (d * xd) | |
d *= xd | |
yield 16 * n // d | |
N += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment