08-16-2022, 12:21 AM
the simplest and fast way to calculate pi is to use the Gauss–Legendre algorithm https://en.wikipedia.org/wiki/Gauss%E2%8..._algorithm
the Pi - Chudnovsky with binary splitting is much faster here's a version in FreeBasic https://www.freebasic.net/forum/viewtopi...85#p178885
all calculations need to be performed to full precision
the Pi - Chudnovsky with binary splitting is much faster here's a version in FreeBasic https://www.freebasic.net/forum/viewtopi...85#p178885
all calculations need to be performed to full precision
Code: (Select All)
digits=100
pow2=1
c0=0: ak = c0: bk = c0: ab = c0: asq = c0
c1=1: a = c1: ck = c1
c2=2: b = c2
c05=.5: sum = c05
b=sqr(b)
b=c1/b
for k=0 to fix(log(digits)*1.44269504088896)
ak=a+b
ak=c05*ak
ab=a*b
bk=sqr(ab)
asq=ak*ak
ck=asq-ab
pow2=pow2*2
tmp=ck*pow2
sum=sum-tmp
a = ak: b = bk
next
tmp=asq/sum
pie=c2*tmp
print pie