MCPcopy Create free account
hub / github.com/geekcomputers/Python / pi

Function pi

primelib/primelib.py:43–61  ·  view source on GitHub ↗

maxK: nuber of iterations prec: precision of decimal places disp: number of decimal places shown

(maxK=70, prec=1008, disp=1007)

Source from the content-addressed store, hash-verified

41
42
43def pi(maxK=70, prec=1008, disp=1007):
44 """
45 maxK: nuber of iterations
46 prec: precision of decimal places
47 disp: number of decimal places shown
48 """
49 from decimal import Decimal as Dec, getcontext as gc
50
51 gc().prec = prec
52 K, M, L, X, S = 6, 1, 13591409, 1, 13591409
53 for k in range(1, maxK + 1):
54 M = Dec((K**3 - (K << 4)) * M / k**3)
55 L += 545140134
56 X *= -262537412640768000
57 S += Dec(M * L) / X
58 K += 12
59 pi = 426880 * Dec(10005).sqrt() / S
60 pi = Dec(str(pi)[:disp])
61 return pi
62
63
64def isPrime(number):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected