; ; rta_tst0_pi_plouffe.rta ; ======================= ; ; Pi computation by Plouffes formula. It is: ; ; 4 2 1 1 n ; pi = summe (----- - ----- - ----- - -----)(1/16) ; [n=0..] 8*n+1 8*n+4 8*n+5 8*n+6 ; ; Init ; _name Pi clr pi ; 0 to variable pi clr restgl ; 0 to variable "restgl" mov n -1 ; -1 to variable n mov 8n -8 ; -8 to variable "-8" mov 1/16 0.0625 ; 0.0625 to variable "1/16" mov f1 16 ; 16 to f1 ... cls ; "clear screen": clear output text area pause Pi~Formula~of~Plouffe~... ; user message ; ; The Loop ; loop: add n 1 ; cycle counter (not needed) add 8n 8 ; the variable 8n is 8*n mov z1 4 mov n1 8n add n1 1 div z1 n1 ; 1st term mov z2 2 mov n2 8n add n2 4 div z2 n2 ; 2nd term mov z3 1 mov n3 8n add n3 5 div z3 n3 ; 3rd term mov z4 1 mov n4 8n add n4 6 div z4 n4 ; 4th term mul f1 1/16 ; 1/16 power n clr restgl ; add restgl z1 sub restgl z2 sub restgl z3 sub restgl z4 mul restgl f1 ; new summand add pi restgl ; add to pi printn n 4 0 ; output ... prints :~ ; of : and a space printn pi 1 18 ; of pi with 1.18 digits prints \ ; output of a newline mov absx restgl abs absx output pi Continue~... ; Cyclic dialog cmpgt absx 1E-18 loop ; gt: new loop save rta_pi output pi Computation~finished.~Result~is~also~written~into~file~rta_pi.txt. exit _end