Subject: Re: [boost] floating point FUD
From: Thomas Klimpel (Thomas.Klimpel_at_[hidden])
Date: 2010-01-23 17:49:24
Rutger ter Borg wrote:
> I'm unable to reproduce, see below.
Oh no, I should have typed
$ g++ test_fp.cpp -DNDEBUG -O2 -msse2 -mfpmath=sse -Wall
to force the compiler on my 32-bit system to really use sse floating point instructions instead of the 387 instructions (I guess the default is -mfpmath=387 for 32-bit intel systems and -mfpmath=sse for 64-bit intel systems). I was already wondering why the bugs were so easy to trigger, because I remembered that some of the bugs in the test program were only rarely triggered when occurring in real life code. I guess it's at least 2048 times easier to trigger such bugs with 387 instructions than with "normal" floating point instructions (like sse). It might well be that sse floating point instructions don't allow to trigger some of the bugs at all.
So on a 64-bit intel system, typing
$ g++ test_fp.cpp -DNDEBUG -O2 -mfpmath=387 -Wall
should trigger the bugs. I get different output when I use -O3 instead of -O2, but -O2 seems to trigger more bugs.
> Looking at your code, you might want to
> give std::fabs() a try over abs(). I remember having been bitten hard by
> that one-letter difference.
You spotted one of the bugs, very good. This bug is actually one of my favorites. I tend to fix this bug by writing "std::abs".
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk