
Create a program to continually calculate and output the next decimal digit of   



π


{\displaystyle \pi }

   (pi).

The program should continue forever (until it is aborted by the user) calculating and outputting each decimal digit in succession.

The output should be a decimal sequence beginning   3.14159265 ...



Note: this task is about   calculating   pi.   For information on built-in pi constants see Real constants and functions.



Related Task Arithmetic-geometric mean/Calculate Pi

% Implemented by Arjun Sunel
-module(pi_calculation).
-export([main/0]).
 
main() ->
	pi(1,0,1,1,3,3,0).
 
pi(Q,R,T,K,N,L,C)   ->
 
	if C=:=50 ->
		io:format("\n"),
		pi(Q,R,T,K,N,L,0)  ;
 
	true ->
 
		if 
			(4*Q + R-T) < (N*T) -> 
			io:format("~p",[N]),
	 		P = 10*(R-N*T),
	 		pi(Q*10 , P, T , K , ((10*(3*Q+R)) div T)-10*N , L,C+1);
 
		true ->
			P = (2*Q+R)*L,
			M = (Q*(7*K)+2+(R*L)) div (T*L),
			H  = L+2,
			J =K+ 1,
			pi(Q*K, P , T*L ,J,M,H,C)
	 	end
 	end.	
 