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

Subversion Repositories plasma

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

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 336 rhoads
int putchar(char ch)
4 137 rhoads
{
5
   *(int*)0x20000000 = ch;
6 336 rhoads
   return 0;
7 137 rhoads
}
8 31 rhoads
 
9 137 rhoads
void OS_InterruptServiceRoutine(unsigned int status)
10
{
11
   (void)status;
12
}
13
#endif
14
 
15 31 rhoads
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 137 rhoads
int main()
27 31 rhoads
{
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 137 rhoads
   return 0;
34 31 rhoads
}
35
 

powered by: WebSVN 2.1.0

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