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

Subversion Repositories mips789

[/] [mips789/] [tags/] [arelease/] [bench/] [cal_PI/] [cal_pi.c] - Blame information for rev 35

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

Line No. Rev Author Line
1 35 mcupro
/******************************************************************
2
 *                                                                *
3
 *    Author: Liwei                                               *
4
 *                                                                *
5
 *    This file is part of the "mips789" project.                 *
6
 *    Downloaded from:                                            *
7
 *    http://www.opencores.org/pdownloads.cgi/list/mips789        *
8
 *                                                                *
9
 *    If you encountered any problem, please contact me via       *
10
 *    Email:mcupro@opencores.org  or mcupro@163.com               *
11
 *                                                                *
12
 ******************************************************************/
13
 
14
 
15
 
16 15 mcupro
#include "..\..\clib\dvc_lib.h"
17
 
18
void print_num(unsigned long num)
19
{
20
    unsigned long digit,offset ;
21
    for(offset=1000;offset;offset/=10)
22
    {
23
        digit=num/offset ;
24
        uart0_putc('0'+digit);
25
        num-=digit*offset ;
26
    }
27
}
28
 
29
long a=10000,b=0,c=56,d=0,e=0,f[57]={0},g=0 ;
30
 
31
void cal_PI(void)
32
{
33
    uart0_putstr("\nPI = ");
34
    a=10000 ;
35
    b=0 ;
36
    c=56 ;
37
    d=0 ;
38
    e=0 ;
39
    g=0 ;
40
    for(;b-c;)f[b++]=a/5 ;
41
    for(;d=0,g=c*2;c-=14,print_num(e+d/a),e=d%a)
42
    for(b=c;d+=f[b]*a,f[b]=d%--g,d/=g--,--b;d*=b);
43
    uart0_putc('\n');
44
}
45
 
46
main2()
47
{
48
 
49
while(1)
50
{
51
    uart0_putstr("Hello CPU World ,this is  MIPS789...");
52
cal_PI();
53
}
54
 
55
}

powered by: WebSVN 2.1.0

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