maxK: nuber of iterations prec: precision of decimal places disp: number of decimal places shown
(maxK=70, prec=1008, disp=1007)
| 41 | |
| 42 | |
| 43 | def 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 | |
| 64 | def isPrime(number): |
nothing calls this directly
no outgoing calls
no test coverage detected