Re: Interesting behavior of double.NaN
Mark Hurd <[email protected]> Tue, 24 Mar 2009 19:55:05 +1030
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Mar 24, 2009 at 7:26 PM, Per Bolmstedt <[email protected]> wrote: > On Tue, 24 Mar 2009 09:43:20 +0100, Brink, Paul ten <[email protected]> wrote: > >> Thanks, John, I was aware of this. But I am using this comparison >> in a property setter where you normally take some action if the >> new property value is not equal to the previous property value. > > This sounds like an abuse of the equality test that's now come back to bite you. Some modifiable items may have equality check implementations with even more unexpected behavior than doubles. > > Wouldn't it be possible for you to use an "IsModified" strategy instead? You can also use the more primitive equality tests like Object.Equals, or even IComparer.CompareTo, both of which return equal. I.e. Double.NaN.Equals(Double.NaN) and Object.Equals(Double.NaN, Double.NaN) and CType(Double.NaN,IComparable).CompareTo(Double.NaN)=0 all return True. -- Regards, Mark Hurd, B.Sc.(Ma.)(Hons.) =================================== View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives