This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: code optimizations and numerical research


On Mon 16 May 05, 11:04 AM, Ian Lance Taylor <ian@airs.com> said:
> p@dirac.org (Peter Jay Salzman) writes:
> 
> > The man page claims that "-ffast-math" may produce wrong results for
> > programs that depend on "an exact implementation of IEEE or ISO
> > rules/specifications for math functions."
> > 
> > What exactly does this vague sentence mean?
> 
> Read "What Every Computer Scientist Should Know about Floating-Point
> Arithmetic:" http://www.validlab.com/goldberg/paper.pdf
 
Not exactly light reading.  But it does look like something I really need to
read.  I've printed this behemoth out.

> Unfortunately it's rather hard to understand what these optimizations do
> without becoming something of an expert.
 
I was afraid of that.

> As a general rule of thumb, if you do not know the details of IEEE
> floating point format, and you are not calculating your precise error
> intervals and writing code which relies on them to, e.g., converge--in
> other words, if you are just writing code that happens to use floating
> point--then you will probably do just fine with -ffast-math.

Just to make sure --- so you're saying that even though I'm enabling SIGFPE
to catch exceptions:


   void fpe_trap_enable(void)
   {
      /* Enable FPE's, by default all FPE's will not raise a signal when 
       * they happen... see fenv.h for magic constants. 
       *
       * FE_INEXACT     inexact result - don't do this!  It always occurs!
       * FE_DIVBYZERO   division by zero
       * FE_UNDERFLOW   result not representable due to underflow
       * FE_OVERFLOW    result not representable due to overflow
       * FE_INVALID     invalid operation
       */

     feenableexcept( FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID);
   }



	{  /* Setup a signal handler for SIGFPE */
		struct sigaction action;
  
		memset(&action, 0, sizeof(action));
		action.sa_sigaction = fpe_callback;    /* which callback function  */
		sigemptyset(&action.sa_mask);          /* other signals to block   */
		action.sa_flags = SA_SIGINFO;          /* give details to callback */
  
		if (sigaction(SIGFPE, &action, 0))
			die("Failed to register signal handler.");
	}


all the talk about -ffast-math making the compiler assume that args and
results of math operations are correct and finite has no bearing on either
my code (which certainly doesn't do what you described above) or my enabling
and catching FPE exceptions?

Thanks very much!
Pete

-- 
Every theory is killed sooner or later, but if the theory has good in it,
that good is embodied and continued in the next theory. -- Albert Einstein

GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E  70A9 A3B9 1945 67EA 951D


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]