08-16-2022, 01:25 AM
(08-16-2022, 12:21 AM)Jack Wrote: 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
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
@Jack
I can't say I'm a fan of this one. Digits variable at 100 runs 6 iterations. I tried other iterations with less accurate or completely skewed results. So the...
Code: (Select All)
fix(log(digits)*1.44269504088896)
...is lost on me. at digits = 100 the output was: 3.141697. Is there any way to get that more accurate and produce more digits?
Pete