Floating point optimizations

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

 



Hi,

we are currently investigating some numerical algorithms and the claim
appeared that a C statement like
  x = c - (c - a);
would be easily transformed into
  x = a;
by the compiler. Now investigating this with a vanilla GCC 4.1.2 failed
to support the claim. Compiling the below program with -O3 -ffast-math
keeps the computation of x. The output shows x is different from a. The
question is, is there some compiler switch or the like to get GCC to
make the above transformation? I searched the docs but had the
impression that all relevant flags should be included in the above two
(especially ffast-math).

Please let me know if you need any additional information or if this is
the wrong list for this kind of question.

Cheers,
Christian

------8<--------
#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
  double a, x;
  double c;

  scanf("%lf", &a);
  c = ((1 << 27) + 1) * a;
  x = c - (c - a);

  printf("a = %e(%a)\n", a, a);
  printf("x = %e(%a)\n", x, x);
}
------8<--------

-- 
Christian Keil                        /"\
Institute for Reliable Computing      \ /    ASCII Ribbon Campaign
Hamburg University of Technology       X  against HTML email & vCards
mail:c.keil@xxxxxxxxxxxxx             / \

[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