
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

 
use 'java:java.math' stand-alone
 
def zero: 0 -> math/BigInteger::valueOf;
def one: 1 -> math/BigInteger::valueOf;
def two: 2 -> math/BigInteger::valueOf;
def three: 3 -> math/BigInteger::valueOf;
def four: 4 -> math/BigInteger::valueOf;
def seven: 7 -> math/BigInteger::valueOf;
def ten: 10 -> math/BigInteger::valueOf;
 
templates g&{q:, r:, t:, k:, n:, l:}
  def u: $four -> q::multiply -> r::add;
  def nt: $n -> t::multiply;
  $ -> #
  when <?($t -> u::subtract <..~$nt>)> do
    $n -> !OUT::write
    $ -> \(<=1> $!\) -> '.' -> !OUT::write
    def v: $three -> q::multiply -> r::add -> ten::multiply;
    def quot: $t -> v::divide;
    0 -> g&{q: $ten -> q::multiply,
      r: $nt -> r::subtract -> ten::multiply,
      t: $t,
      k: $k,
      n: $ten -> n::multiply -> quot::subtract,
      l: $l } !
  otherwise
    def tl: $t -> l::multiply;
    def rl: $r -> l::multiply;
    def term: $q -> seven::multiply -> k::multiply -> two::add -> rl::add;
    $ -> g&{q: $q -> k::multiply,
      r: $two -> q::multiply -> r::add -> l::multiply,
      t: $tl,
      k: $k -> one::add,
      n: $tl -> term::divide,
      l: $l -> two::add} !
end g
 
1 -> g&{q:$one, r:$zero, t:$one, k:$one, n:$three, l:$three} -> !VOID
 