Re: How to overload == for System.Double

Stoyan Damov <[email protected]> Fri, 2 Feb 2007 22:22:58 +0200
Newsgroups gmane.comp.windows.devel.dotnet.cx
Message-ID <[email protected]>
On 2/2/07, Marc Brooks <[email protected]> wrote:
> > FYI, there are Double.Epsilon and Single.Epsilon fields re tollerance.
>
> Which is the smallest value that can be added/subtracted FROM ZERO
> that will give a different result.  Thus it's only applicable when you
> are near zero...  If you subtract two large numbers, where the
> Mantissa of the float is shifted far enough away from 1 that there are
> lost bits of precision, then comparing two values may give you
> surprising results.
>
> Check this article:
> http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
>

Thanks man! I haven't needed yet to compare doubles/floats for
equality but I've skimmed over the article and bookmarked it forever
:) I'll also be the 1st to use your code because looking at it and
back at the article - it implements AlmostEqual2sComplement in C# +
adds the checks for NaNs and infinities.

Cheers

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com