
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

n = 1000
long = 10 * int(n / 4)
needdecimal = 1 //true
dim a(long)
nines = 0
predigit = 0  // {First predigit is a 0}
 
for j = 1 to long
  a(j-1) = 2  // {Start with 2s}
next j
 
for j = 1 to n
  q = 0
  for i = long to 1 step -1
    //  {Work backwards}
    x   = 10*a(i-1) + q*i
    a(i-1) = mod(x, (2*i - 1))
    q  = int(x / (2*i - 1))
  next i
  a(0) = mod(q, 10)
  q = int(q / 10)
  if q = 9 then
    nines = nines + 1
  else
    if q = 10 then
      d = predigit+1
      gosub outputd
      if nines > 0 then
        for k = 1 to nines
          d =  0
          gosub outputd
        next k
      end if
      predigit = 0
      nines = 0
    else
      d = predigit
      gosub outputd
      predigit = q
      if nines <> 0 then
        for k = 1 to nines
          d =  9
          gosub outputd
        next k
        nines = 0
      end if
    end if
  end if
next j
print predigit
end
 
label outputd
if needdecimal then
  if d = 0 then return : fi
  print d;
  print ".";
  needdecimal = 0 //false
else
  print "", d;
endif
return