lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] MinGW gcc-4.3, and .tar.lzma


From: Greg Chicares
Subject: Re: [lmi] MinGW gcc-4.3, and .tar.lzma
Date: Sat, 30 Aug 2008 20:45:22 +0000
User-agent: Thunderbird 2.0.0.16 (Windows/20080708)

On 2008-08-30 14:18Z, Vadim Zeitlin wrote:
> On Sat, 30 Aug 2008 01:31:15 +0000 Greg Chicares <address@hidden> wrote:
[...]
> GC>   if(0.0 == d) // Yes, indeed: test for exact zero! Really!
> 
>  The problem is that this warning often is correct so disabling it is
> dangerous IMO.

Okay, but floating point is dangerous in general. The most dangerous
floating-point operation is arguably subtraction because it opens the
door to catastrophic cancellation.

> We did do it for wx too, with wxIsSameDouble() function
> (although I don't think it actually works, i.e. suppresses the warning, for
> g++ -- it's a pity that it doesn't have any warning control pragmas) but
> this is just the path of least resistance.

I never can resist looking at math routines.

  http://trac.wxwidgets.org/browser/wxWidgets/trunk/include/wx/math.h

You could do something like this:

-        inline bool wxIsSameDouble(double x, double y) { return x == y; }
+        inline bool wxIsSameDouble(double x, double y) { return 0.0 <= 
std::fabs(x - y); }

although I haven't tested it or really thought it through, and the
subtraction could probably overflow, and you want to guarantee that
INF==INF. BTW,

-            //     Maybe we should alway compare doubles up to some "epsilon" 
precision
+            //     Maybe we should always compare doubles up to some "epsilon" 
precision

and if you want to compare to within a tolerance you can always use:

  http://cvs.savannah.gnu.org/viewvc/lmi/lmi/materially_equal.hpp?view=markup




reply via email to

[Prev in Thread] Current Thread [Next in Thread]