4 import core.stdc.stdio;
7 const int LONG_TIME=4000;
13 int main(char[][] args)
15 time_t startime, endtime;
18 if (args.length == 2) {
19 sscanf(&args[1][0],"%d",&q);
21 printf("Usage: pi [precision]\n");
27 printf("Precision was too low, running with precision of 0.\n");
33 printf("Be prepared to wait a while...\n");
36 // Compute one more digit than we display to compensate for rounding
50 // Return to the number of digits we want to display
55 printf("pi = %d.",cast(int)(p[0]));
56 for (i = 1; i <= q; i++)
57 printf("%d",cast(int)(p[i]));
59 printf("%lld seconds to compute pi with a precision of %d digits.\n", cast(long)(endtime-startime),q);
69 div(s); /* t[] = 1/s */
76 if (((n-1) / 2) % 2 == 0)
87 for (j = q; j >= 0; j--)
89 if (t[j] + p[j] > 9) {
101 for (j = q; j >= 0; j--)
109 void mul(int multiplier)
113 int carry = 0, digit = 0;
115 for (i = q; i >= 0; i--) {
116 b = (t[i] * multiplier + carry);
119 t[i] = cast(byte)digit;
125 void div(int divisor)
128 int quotient, remainder = 0;
132 b = (10 * remainder + x);
133 quotient = b / divisor;
134 remainder = b % divisor;
135 x = cast(byte)quotient;
143 for (i = 0; i <= q; i++) {
144 c = (10 * d + p[i]) / 4;
145 d = (10 * d + p[i]) % 4;
156 for (i = q; i >= 0; i--) {
157 d = (p[i] * 4 + c) % 10;
158 c = (p[i] * 4 + c) / 10;
167 for (k = 0; k <= q; k++)