Skip to content

Instantly share code, notes, and snippets.

@antimatter15
Created June 14, 2015 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antimatter15/b8042129c088f2856b3a to your computer and use it in GitHub Desktop.
Save antimatter15/b8042129c088f2856b3a to your computer and use it in GitHub Desktop.
This implementation is useless for more than 47 digits.
function* calculatePi(){
let [q, r, t, k, n, l] = [1, 0, 1, 1, 3, 3];
while(true){
if(4 * q + r - t < n * t){
yield n
nr = 10 * (r - n * t)
n = ((10 *(3 * q + r)) % t) - 10 * n
q *= 10
r = nr
}else{
nr = (2*q+r)*l
nn = (q*(7*k)+2+(r*l))%(t*l)
q *= k
t *= l
l += 2
k += 1
n = nn
r = nr
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment