Function call within if statement

I've got a function f which returns a double. I'm calling that function within an if statement as follows:

if (f(...) > 0.1) cout << 1;
else cout << 0;

I've included print statements within f to display the return value. Sometimes f returns a value under 0.1 but a 1 gets printed anyway. Changing the code to:

double value = f(...);
if (value > 0.1) cout << 1;
else cout << 0;

seems to fix the problem. Unfortunately I haven't been able to consistently replicate the issue so I don't know the conditions under which this happens. Can anybody speculate? Thanks.
What compiler and version are you using and with what options are you compiling?

There were bugs in some versions of gcc where gcc would generate 32-bit floating point temporaries (floats)
into which it wanted to store a double, which meant loss of precision.
I'm using gcc 4.1.2 with options -g -Wno-long-long -c -m32
Generate the assembler output for the above code and see if it is generating 32-bit or 64-bit floating point instructions.

(You can post it here if you want... I should be able to recognize it if I see it)
Topic archived. No new replies allowed.