]> rtime.felk.cvut.cz Git - fpga/plasma.git/blob - tools/pi.c
Local copy of Plasma MIPS project.
[fpga/plasma.git] / tools / pi.c
1 /*Calculate the value of PI.  Takes a long time!*/
2 #ifndef WIN32
3 int putchar(char ch)
4 {
5    *(int*)0x20000000 = ch;
6    return 0;
7 }
8
9 void OS_InterruptServiceRoutine(unsigned int status)
10 {
11    (void)status;
12 }
13 #endif
14
15 void print_num(unsigned long num)
16 {
17    unsigned long digit,offset;
18    for(offset=1000;offset;offset/=10) {
19       digit=num/offset;
20       putchar(digit+'0');
21       num-=digit*offset;
22    }
23 }
24
25 long a=10000,b,c=56,d,e,f[57],g;
26 int main()
27 {
28    long a5=a/5;
29    for(;b-c;) f[b++]=a5;
30    for(;d=0,g=c*2;c-=14,print_num(e+d/a),e=d%a)for(b=c;d+=f[b]*a,
31      f[b]=d%--g,d/=g--,--b;d*=b);
32    putchar('\n');
33    return 0;
34 }
35