public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Help: math functions (sin,cos,tan,sqrt)
@ 2004-01-06  7:03 sun.wizard
  0 siblings, 0 replies; only message in thread
From: sun.wizard @ 2004-01-06  7:03 UTC (permalink / raw)
  To: gcc-help

Hi!
    Now i am using arm-elf-gcc 3.03 compile program for ATMEL ARM7TDMI, I met a trouble that the math library seems some bugs!
 
    This is the enviroment:
 
    CPU:
        ATMEL ARM7TDMI 40008
    RAM:
        256KB (in CPU)
    GCC:
        arm-elf-gcc 3.03
 
    I used such functions in my program:
        * sin
        * cos
        * tan
        * sqrt
        * printf
 
 
    [ Problem 1 ]
 ----------------------------------------------
    void testFloat()
    {
        const float pi = 3.14;
        float f = tan(pi / 4), x, y;                      <------   f = 1.072692E+9 ! wrong! (while sometimes it's ok in other function)
        int i;
    
        printf("sin(pi/4) = %f\n", sin(pi/4));
        getch();
        printf("tan(pi/4) = %f\n", tan(pi/4));
        getch();
        printf("atan(pi/4) = %f\n", atan(pi/4));
        getch();
        
        get_key();
    }
    *** Does something wrong with tan()?


 
    [ Problem 2 ]
 ----------------------------------------------
    At first the produced binary size is 67,040(bytes)
 
    But when i insert into 500 lines such code:
 
    f = sqrt(sin(pi/4) * cos(pi/4));
    ...
 
    Now the produced binary size became to 134,696(bytes)!
    *** Why it cost so much?
 
    [ Problem 3 ]
 ----------------------------------------------
    void testFloat2()
    {
        const float pi = 3.14;
        float f, g, x;
 
        f = sin(pi/4);                                   <------   f = 7.068252E-1
        g = cos(pi/4);                                   <------   g = 7.073882E-1
        x = f * g;                                       <------   f = 4.999998E-1
        x = sqrt(x);                                     <------   Died here!
    }
    *** It seems it break the system, does these functions need very large memory space? If so, is the space in .BSS section or other defined stack?
 
 
    [ Problem 4 ]
 ----------------------------------------------
    printf("sizeof(double) = %d", (unsigned int)sizeof(double));
 
    When I used much math function, sizeof(double) maybe not 8! I met 500!
    It seems a big joke!
 
    [ Problem 5 ]
 ----------------------------------------------
    When many math function used in program, any dynamic parameters function such as sprintf(...) will failed!
    eg. sprintf(buf, "hello %s", "john");
        the result buf maybe "hello %s" AND ALSO maybe ""!
    It seems that the function stack was breaked!
 
    [ I think ]
 ----------------------------------------------
    I had hear that ARM7TDMI have no hard floating point, *** Does the CFLAG need -msoft-float option? but when I used -msoft-float, the compile told me: "xxxx.o uses hard floating point, whereas module.elf uses soft floating point".
 
    I saw this news on the GCC home page:

    "August 27, 2003 Nicolas Pitre has contributed his hand-coded floating-point support code for ARM...."

    *** Does the newest arm-elf-gcc contains the soft-float library?
 
    IF NOT
 
    *** Need I rebuild the libc.a and libgcc.a to support soft floating? and where to get the source code?
 
    CAN YOU HELP ME OUT OF THIS TROUBLE? THANKS VERY MUCH!
 
 
 
Thanks!
 
        2003/1/6
        Ken

========================================================
网易VIP收费邮箱两周年超值优惠! 满1赠6!!           http://vip.163.com

中国最大的免费邮箱在等你 25兆空间4兆附件!      http://mail.163.com

点击网易泡泡惊喜无限 全免费手机短信任你发!      http://popo.163.com

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-01-06  7:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-06  7:03 Help: math functions (sin,cos,tan,sqrt) sun.wizard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).