[Clp] patch for Visual C++ floating-point model problem

Michael Hennebry hennebry at web.cs.ndsu.nodak.edu
Sun Aug 10 23:38:34 EDT 2008


On Sun, 10 Aug 2008, Arno Schödl wrote:

> > The basic issue is ancient. Do not compare floats without a precision guard.
>
> I am sure John is aware of the general problem. The problem here is a little more specific and only occurs with x87 floating point. The problem goes away with x64, which uses SSE2 floating point. Reviewing the code is still a good idea...
>
> Matthew: I already tried these MSVC settings. From the spec, /fp:precise should help, but is slower. In addition, it did not do the right thing in Visual C++ 2008, probably compiler bug. /fp:strict fixed the problem, but is even slower. gcc uses the equivalent of /fp:fast as default. Overall, I'd favor this most general model.

IIRC there is a bit in the x86 processors that when flipped will
effectively lop 16 bits off the floating point registers.
I suspect that flipping that bit would involve writing some assembler.
That should solve the problem so long as you don't invoke any library
functions that relay on 80-bit floating point.
IIRC printf is one of them.

As noted, comparing floating point numbers
for equality is rarely the right thing.

Deciding what to do instead can be tricky.

-- 
Michael   hennebry at web.cs.ndsu.NoDak.edu
"Those parts of the system that you can hit with a hammer (not advised)
are called Hardware;  those program instructions that you can only
curse at are called Software."





More information about the Clp mailing list