Skip to content

Instantly share code, notes, and snippets.

@z2s8
Last active August 29, 2015 14:07
Show Gist options
  • Save z2s8/c5bd509be81d54243320 to your computer and use it in GitHub Desktop.
Save z2s8/c5bd509be81d54243320 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(1)/Decimal(str(16**k)))*( (Decimal(4)/Decimal(str(8*k+1)))-(Decimal(2)/Decimal(str(8*k+4)))-(Decimal(1)/Decimal(str(8*k+5)))-(Decimal(1)/Decimal(str(8*k+6))) )
print (k)
print (pi)
print (timeit(calc, number = 1))
@z2s8
Copy link
Author

z2s8 commented Oct 16, 2014

  • Kivettem egy Decimal() atalakitast pi elejerol mert ugyis minden tagja decimal -> gyorsabb kicsit
  • Nem egeszeket stringre alakitottam -> pontosabb, de lassabb
    • Miert?
    • 1.12345678901234567 == 1.12345678901234568 -> True mert float
    • Decimal('1.1') == Decimal(1.1) -> False
    • print(Decimal('1.1'), Decimal(1.1)) -> 1.1 es 1.100000000000000088817841970012523233890533447265625

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment