public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Floating point optimizations
@ 2008-04-03 17:00 Christian Keil
  2008-04-03 17:27 ` John Fine
  2008-04-03 18:24 ` Alexander Monakov
  0 siblings, 2 replies; 10+ messages in thread
From: Christian Keil @ 2008-04-03 17:00 UTC (permalink / raw)
  To: gcc-help

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@tu-harburg.de             / \

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-04-05 19:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-03 17:00 Floating point optimizations Christian Keil
2008-04-03 17:27 ` John Fine
2008-04-04 12:04   ` Christian Keil
2008-04-03 18:24 ` Alexander Monakov
2008-04-04 15:48   ` Christian Keil
2008-04-05  1:15   ` Tim Prince
2008-04-05 13:07     ` Andrew Haley
2008-04-05 13:32       ` NightStrike
2008-04-05 19:05         ` Tim Prince
2008-04-05 21:26         ` me22

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).