Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Chudnovsky algorithm in python codes

def compute_pi(n):
    decimal.getcontext().prec = n + 1
    C = 426880 * decimal.Decimal(10005).sqrt()
    K = 6
    M = 1
    X = 1
    L = 13591409
    S = L
    for i in range(1, n):
        M = M * ((1728*i*i*i)-(2592*i*i)+(1104*i)-120)/(i*i*i)
        L += 545140134
        X *= -262537412640768000
        M=decimal.Decimal(M)
        L=decimal.Decimal(L)
        S += decimal.Decimal((M*L) / X)
    pi = C / S
    return pi
Source by levelup.gitconnected.com #
 
PREVIOUS NEXT
Tagged: #Chudnovsky #algorithm #python #codes
ADD COMMENT
Topic
Name
5+5 =