On Sat, 15 Jan 2005 11:06:10 -0700, Elijah Newren <newren@xxxxxxxxx> wrote: > I have some code where I need to know whether two floating point > expressions are different (and, if they are, whether their difference > is positive). Unsafe optimizations of some sort seem to be made (I'm > compiling at "-O2 -funroll-loops", though I can demonstrate a simple > test case that fails with no optimizations). I found a solution, but > it assumes the compiler isn't smart enough to aggressively inline > functions. > > My question is: How can I write my code so that it functions correctly > even with potentially future versions of gcc that can aggressively > inline code in its optimizer? I know it's kind of lame to respond to my own email, but I found the problem; it's one of those PEBKAC ones. :-) I really should have remembered or been aware of -ffloat-store (I've read it before, but I didn't let it sink in despite the coverage of floating point arithmetic I've had in my courses...*sigh*). I guess all this debugging and making a fool of myself was what I needed to hammer home that if I'm critically worried about floating point correctness then I have to store expressions in temporaries, then compare the expressions, and be sure to compile with -ffloat-store. Sorry for wasting everyone's time, Elijah