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

Subversion Repositories mlite

[/] [mlite/] [trunk/] [tools/] [pi.c] - Blame information for rev 240

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
void putchar(char ch)
4
{
5
   *(int*)0x20000000 = ch;
6
}
7 31 rhoads
 
8 137 rhoads
void OS_InterruptServiceRoutine(unsigned int status)
9
{
10
   (void)status;
11
}
12
#endif
13
 
14 31 rhoads
void print_num(unsigned long num)
15
{
16
   unsigned long digit,offset;
17
   for(offset=1000;offset;offset/=10) {
18
      digit=num/offset;
19
      putchar(digit+'0');
20
      num-=digit*offset;
21
   }
22
}
23
 
24
long a=10000,b,c=56,d,e,f[57],g;
25 137 rhoads
int main()
26 31 rhoads
{
27
   long a5=a/5;
28
   for(;b-c;) f[b++]=a5;
29
   for(;d=0,g=c*2;c-=14,print_num(e+d/a),e=d%a)for(b=c;d+=f[b]*a,
30
     f[b]=d%--g,d/=g--,--b;d*=b);
31
   putchar('\n');
32 137 rhoads
   return 0;
33 31 rhoads
}
34
 

powered by: WebSVN 2.1.0

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