
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

V ndigits = 0
V q = BigInt(1)
V r = BigInt(0)
V t = q
V k = q
V n = BigInt(3)
V l = n
 
V first = 1B
L ndigits < 1'000
   I 4 * q + r - t < n * t
      print(n, end' ‘’)
      ndigits++
      I ndigits % 70 == 0
         print()
      I first
         first = 0B
         print(‘.’, end' ‘’)
      V nr = 10 * (r - n * t)
      n = ((10 * (3 * q + r)) I/ t) - 10 * n
      q *= 10
      r = nr
   E
      V nr = (2 * q + r) * l
      V nn = (q * (7 * k + 2) + r * l) I/ (t * l)
      q *= k
      t *= l
      l += 2
      k++
      n = nn
      r = nr