[Top][All Lists]

[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 (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.


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

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

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


reply via email to

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