# (Unknown)

```The program below, pi.b, is supposed to calculate Pi to many places.
The Python version works and I copied it as literally as possible
(since I don't really understand the algorythm).
When I run it (after > limbo -g pi.b) on my system using the debugger
it has a segmentation violation the first time it comes to the print()
statement.
This also causes an NT violation and the Inferno emu dies.

# Print digits of pi forever.
# Borrowed from a Python demo "pi.py":
#   >> The algorithm, using Python's 'big' integers ("bignums"), works
#   >>with continued fractions, and was conceived by Lambert Meertens.
#
# See also the ABC Programmer's Handbook, by Geurts, Meertens & Pemberton,

implement Pi;

include "sys.m";
sys: Sys;
print: import sys;

include "draw.m";
Context: import Draw;

Pi: module
{
init:   fn(ctxt: ref Context, argv: list of string);
};

init(nil: ref Context, argv: list of string)
{
k,a,b,a1,b1,p,q,d,d1 : big;
first := 1;
k = big 2;
a = big 4;
b = big 1;
a1 = big 12;
b1 = big 4;
for(;;) {
# Next approximation
p = k*k;
q = big 2*k+big 1;
k++;
a = a1;
b = b1;
a1 = p*a+q*a1;
b1 = p*b+q*b1;
# Print common digits
d = a/b;
d1 = a1/b1;
while(d == d1) {
print("%bd", d);
if(first) {
first = 0;
print(".");
}
a = big 10*(a%b);
a1 = big 10*(a1%b1);
d = a/b;
d1 = a1/b1;
}
}
}

```