strange floating point problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi !

I got on my system a strange floating point problem.

Here is the code sequence:

#include <stdio.h>
#define FRAC  4294967296.  /* 2^32 as a double */

unsigned long GetVal(double val)
{
  unsigned long ret_val;

/*this code sequence is used in libntp.*/
  ret_val = (unsigned long) val;
  return ret_val;
}

int main()
{
        double fval = 0.6;

        printf("no bug\n");
        fval = fval * FRAC;
        printf("Float:%f UINT:%lu\n",fval,GetVal(fval));
        printf("HEX:%x\n",GetVal(fval));
        return 0;
}


The output is on
*) Debian PPC gcc-3.3 / Debian i386 gcc-3.3/gcc-3.4/gcc-4.1

Float:2576980377.600000 UINT:2576980377
HEX:99999999

That looks fine for me. But on my ARM system (EP7301) I am using GCC 3.3.6
with softfloat I got following output:

arm-linux-gcc test.c -o test
arm-linux-gcc -O1 test.c -o test
arm-linux-gcc -O2 test.c -o test
arm-linux-gcc -Os test.c -o test

Float:2576980377.600000 UINT:2147483647
HEX:7fffffff

-> Wrong with options O0, O1, O2 and Os
I tried to compile with -O3 and that helps?!
arm-linux-gcc -O3 test.c -o test
Float:2576980377.600000 UINT:2576980377
HEX:99999999
-> Correct! why -O3 helps ???

Also I made a test without softfloat and that looks fine again.
So it seems for me that the softfloat support has a problem.

Any problems known with softfloat on arm?
Nice greetings,
Harald

arm-linux-gcc -v:
Reading specs from
/opt/crossarm7v2/build_arm_nofpu/staging_dir/lib/gcc-lib/arm-linux-uclibc/3.3.6/specs
Configured with:
/opt/crossarm7v2/toolchain_build_arm_nofpu/gcc-3.3.6/configure
--prefix=/opt/crossarm7v2/build_arm_nofpu/staging_dir
--build=i386-pc-linux-gnu --host=i386-pc-linux-gnu
--target=arm-linux-uclibc --enable-languages=c,c++ --enable-shared
--with-gxx-include-dir=/opt/crossarm7v2/build_arm_nofpu/staging_dir/arm-linux-uclibc/include/c++
--disable-__cxa_atexit --enable-target-optspace --with-gnu-ld
--disable-nls --enable-multilib --without-float --enable-sjlj-exceptions
Thread model: posix
gcc version 3.3.6


-- 
Harald Krammer
Brucknerstrasse 33
A - 4020  Linz
AUSTRIA

Mobil +43.(0) 664. 130 59 58
Mail: Harald.Krammer (at) hkr.at



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux