Skip to content

Instantly share code, notes, and snippets.

@z2s8
Last active August 29, 2015 14:07
Show Gist options
  • Save z2s8/1b661bd9ce6d87e1d9a3 to your computer and use it in GitHub Desktop.
Save z2s8/1b661bd9ce6d87e1d9a3 to your computer and use it in GitHub Desktop.
from timeit import timeit
from decimal import *
getcontext().prec = 101
print ("A PI értékének számítása folyamatban...")
def calc (prec = 80):
pi = Decimal(0)
for k in range (prec):
pi = pi + Decimal( (Decimal(1)/Decimal(16**k))*( (Decimal(4)/Decimal(8*k+1))-(Decimal(2)/Decimal(8*k+4))-(Decimal(1)/Decimal(8*k+5))-(Decimal(1)/Decimal(8*k+6)) ) )
print (k)
print (pi)
print (timeit(calc, number = 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment