Floating point problems (accuracy).

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

 



Hi
  We are having a few problems regarding floating point inaccuracies under
  Linux.  Please see the code below.

/*
NOTE:-  This code is an example which demonstrates the sort of problems
        we are getting.
*/
main()
{
  int i;
  double x;

  x = -5.765;
  i = x * 100000;
  printf("I = %d\n",i);

}

/*

We are porting code from a Sun Workstation to a Linux PC.  We have noticed
inaccuracies of double values on the Linux PC.  If we simply compile the
above program e.g "gcc t.c" when we run it we get -576499 when we were really
expecting -576500.  We discovered that if we specify some flags:-

 gcc -march=pentium4 -mfpmath=sse t.c

then suddenly the floating point values become more accurate (i.e. we get the 
value -576500) and other related problems go away (our results agree with the 
same tests running on the Sun).

These flags only seem to work on a pentium4 or an AMD-64, i.e the newer
processor chips.  We would have liked the solution to be more generic.

Does any one know a better way of fixing this?

What was the solution for the older processor chips?

Is there a generic solution?

Thanks for all your help

  Phil Prentice.

[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