Skip to content

Instantly share code, notes, and snippets.

@chuntaro
Created March 15, 2018 02:16
Show Gist options
  • Select an option

  • Save chuntaro/f6da0ca68beaadc86f9f9a70cb17bfb6 to your computer and use it in GitHub Desktop.

Select an option

Save chuntaro/f6da0ca68beaadc86f9f9a70cb17bfb6 to your computer and use it in GitHub Desktop.
円周率をマチンの公式を使って10000桁計算
# 出力結果は3の後ろに小数点が無いのと最後の4桁は未収束の為除いたものが正しい値
import time
def mpiarccot(x):
base = 10 ** (10000 + 4)
a = x
b = 1
pos = base // (a * b)
s = 0
while pos > 1:
pos = base // (a * b)
s += -pos if (2 & b) != 0 else pos
a *= x * x
b += 2
return s
start = time.time()
pi = 4 * (4 * mpiarccot(5) - mpiarccot(239))
elapsed_time = time.time() - start
print(pi)
print(elapsed_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment