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

Subversion Repositories plasma

[/] [plasma/] [tags/] [V2_1/] [tools/] [pi.c] - Blame information for rev 420

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
void putchar(char);
3
 
4
void print_num(unsigned long num)
5
{
6
   unsigned long digit,offset;
7
   for(offset=1000;offset;offset/=10) {
8
      digit=num/offset;
9
      putchar(digit+'0');
10
      num-=digit*offset;
11
   }
12
}
13
 
14
long a=10000,b,c=56,d,e,f[57],g;
15
void main()
16
{
17
   long a5=a/5;
18
   for(;b-c;) f[b++]=a5;
19
   for(;d=0,g=c*2;c-=14,print_num(e+d/a),e=d%a)for(b=c;d+=f[b]*a,
20
     f[b]=d%--g,d/=g--,--b;d*=b);
21
   putchar('\n');
22
}
23
 

powered by: WebSVN 2.1.0

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