September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
24
Task/Pi/Zkl/pi.zkl
Normal file
24
Task/Pi/Zkl/pi.zkl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
var [const] BN=Import("zklBigNum"),
|
||||
one=BN(1), two=BN(2), three=BN(3), four=BN(4), seven=BN(7), ten=BN(10);
|
||||
|
||||
fcn calcPiDigits{
|
||||
reg q=BN(1), r=BN(0), t=BN(1), k=BN(1), n=BN(3), l=BN(3);
|
||||
first:=True; N:=0;
|
||||
while(True){ if((N+=1)==1000){ GarbageMan.collect(); N=0; } // take a deep breath ...
|
||||
if(four*q + r - t < n*t){
|
||||
n.print(); if(first){ print("."); first=False; }
|
||||
nr:=(r - n*t).mul(ten); // 10 * (r - n * t);
|
||||
n=(three*q).add(r).mul(ten) // ((10*(3*q + r))/t) - 10*n;
|
||||
.div(t).sub(ten*n);
|
||||
q.mul(ten); // q *= 10;
|
||||
r=nr;
|
||||
}else{
|
||||
nr:=(two*q).add(r).mul(l); // (2*q + r)*l;
|
||||
nn:=(q*seven).mul(k).add(two) // (q*(7*k + 2) + r*l)/(t*l);
|
||||
.add(r*l).div(t*l);
|
||||
q.mul(k); t.mul(l); // q*=k; t*=l;
|
||||
l.add(two); k.add(one); // l+=2; k++;
|
||||
n=nn; r=nr;
|
||||
}
|
||||
}
|
||||
}();
|
||||
Loading…
Add table
Add a link
Reference in a new issue