OpenCores
URL https://opencores.org/ocsvn/plasma/plasma/trunk

Subversion Repositories plasma

[/] [plasma/] [trunk/] [tools/] [pi.c] - Blame information for rev 200

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 31 rhoads
/*Calculate the value of PI.  Takes a long time!*/
2 137 rhoads
#ifndef WIN32
3 200 rhoads
int InitStack[128];  //used by boot.asm
4
 
5 137 rhoads
void putchar(char ch)
6
{
7
   *(int*)0x20000000 = ch;
8
}
9 31 rhoads
 
10 137 rhoads
void OS_InterruptServiceRoutine(unsigned int status)
11
{
12
   (void)status;
13
}
14
#endif
15
 
16 31 rhoads
void print_num(unsigned long num)
17
{
18
   unsigned long digit,offset;
19
   for(offset=1000;offset;offset/=10) {
20
      digit=num/offset;
21
      putchar(digit+'0');
22
      num-=digit*offset;
23
   }
24
}
25
 
26
long a=10000,b,c=56,d,e,f[57],g;
27 137 rhoads
int main()
28 31 rhoads
{
29
   long a5=a/5;
30
   for(;b-c;) f[b++]=a5;
31
   for(;d=0,g=c*2;c-=14,print_num(e+d/a),e=d%a)for(b=c;d+=f[b]*a,
32
     f[b]=d%--g,d/=g--,--b;d*=b);
33
   putchar('\n');
34 137 rhoads
   return 0;
35 31 rhoads
}
36
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.