[geos-devel] QD (Quad-Double) Approach to Robustness

Mateusz Loskot mateusz at loskot.net
Wed Jun 14 14:01:53 EDT 2006


strk at refractions.net wrote:
> Sounds interesting, I might make some experimentations with it.
> 
> Anyway, I dunno if this could fix the FP problems I reported here: 
> http://geos.refractions.net/pipermail/geos-devel/2006-April/002185.html
> 
> 
> 
> I've been the whole day tracking a problem that turned out to be a 
> consequence of that madness. The attached XML testcase fails with the
>  "inlined" GEOS version but succeeds with the "outlined" version 
> (./configure --disable-inline). I found out that either always 
> outlining Coordinate copy ctor and assignment operator OR letting the
>  compiler syntetize them makes both versions succeed. Logs showed 
> subtle differences in Coordinate double values. These differences 
> triggered a different result from EdgeEnd::compareTo that in turn 
> triggered a different order in the EdgeEndStar components 
> (theoretically to be ordered CCW around the x axis).
> 
> The moral of the story is that we really need a way to make fp 
> operations predictable, or each run will depend on voodoo parameters.
> 
Sandro,

Your test case is incorrect.
You can't compare float numbers as you are doing it in the assert:

assert(tot_check==tot);

especially if you're working with multiplatform library as GEOS.
You can only test how close are both numbers.

There are many problems. float arithmetic on Intel CPUs deos not follow
IEEE 754, different representation of float numbers on varios
architectures: FPU calculations are made on 80 bits numbers (ext.
double) but SSE2 instructions on 64 bits.


There are also other problems regarding optimization. Without any
optimization, intermediate results of calculations can be stored in temp
variables, as a real double, but with optimization they can be stored on
the stack as extended double or in registers

Also, see this:
http://en.wikipedia.org/wiki/Floating_point#Problems_with_floating-point

I'd say all this effor you took is like fightings windmills.
You can't be sure all flags those flags you have used will give you same
 results with comparing doubles using '=='.

In example, here are flags recommended by one of my friend:

g++ -pipe -Os -z combreloc -march=i686 -mfpmath=sse -msse2 unstable.cpp

+ striping code is recommended too:

strip -R .comment -R .note -R .note.ABI-tag -s a.out -o unstable

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the geos-devel mailing list