2 # Copyright (C) 2005-2009, Parrot Foundation.
5 # pidigits N (N = 1000 for shootout)
7 # this requires libgmp (GMP) on the machine
10 # not really optimized yet
11 # modified by Karl Forner to set a default value of N=27 (shootout test default)
14 # return imap(lambda k: (k, 4*k + 2, 0, 2*k + 1), count(1))
36 .yield ($P0, $P1, $P2, $P3)
40 #def compose((aq, ar, as_, at), (bq, br, bs, bt)):
65 .return ($P0, $P1, $P2, $P3)
68 #def extract((q, r, s, t), j):
69 # return (q*j + r) // (s*j + t)
91 .local pmc x0,x1,x2,x3, y, z0,z1,z2,z3, one, three, four
100 three = new 'Integer'
107 y = extract(z0, z1, z2, z3, three)
109 # while y != extract(z, 4):
111 $P0 = extract(z0, z1, z2, z3, four)
112 if y == $P0 goto end_loop2
114 # z = compose(z, x.next())
115 ($P1, $P2, $P3, $P4) = gen_x(one)
116 (z0, z1, z2, z3) = "compose"(z0, z1, z2, z3, $P1, $P2, $P3, $P4)
119 y = extract(z0, z1, z2, z3, three)
122 # z = compose((10, -10*y, 0, 1), z)
132 (z0, z1, z2, z3) = "compose"($P5, $P6, $P7, $P8, z0, z1, z2, z3)
138 # n = int(sys.argv[1])
139 # digits = pi_digits()
141 # for i in xrange(width, n+1, width):
142 # print "%s\t:%d" % ("".join(imap(str, islice(digits, width))), i)
144 # print "%s\t:%d" % ("".join(imap(str, islice(digits, n % width))).ljust(width), n)
150 .local int argc, i, N, width
154 if argc == 1 goto default
189 # vim: expandtab shiftwidth=4 ft=pir: