Re: How to overload == for System.Double
"Eames, Andrew" <[email protected]> Thu, 1 Feb 2007 16:00:14 -0500
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <[email protected]> |
Even if you could do this it is probably a really bad idea. Instead I suggest you write a separate function Static bool Equallish(doubl lhs,double rhs) Andrew -----Original Message----- From: Discussion relating to the specifics of the C# and Managed C++ languages [mailto:[email protected]] On Behalf Of Jack Brown Sent: Thursday, February 01, 2007 3:33 PM To: [email protected] Subject: [DOTNET-CX] How to overload == for System.Double Is it possible? If I put these in a project: public static bool operator ==( double lhs, double rhs ) { } public static bool operator !=( double lhs, double rhs ) { } I get a compiler error: One of the parameters of a binary operator must be the containing type I get this since the overloads are inside a class so they need to have parameters that are of the containing class type. My problem is that I can't put the operator overloads outside a class. The reason I'm doing this is that I want to avoid the problems associated with exact equality comparisons of floating point numbers. I plan/wish to add a Math.Abs(lhs-rhs) <= epsilon where epsilon is some suitably small value. Any help, or at least confirmation that I can't do what I'd like to would be appreciated. -- Jack Brown Controls Engineer Electroimpact, Inc. Desk: 425-609-4988 Cell: 206-617-6482 Office: 425-348-8090 [email protected] =================================== This list is hosted by DevelopMentor(r) http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com -- BEGIN-ANTISPAM-VOTING-LINKS ------------------------------------------------------ NOTE: This message was trained as non-spam. If this is wrong, please correct the training as soon as possible. Teach CanIt if this mail (ID 7375907) is spam: Spam: http://mail-gw.cognex.com/canit/b.php?c=s&i=7375907&m=aef34f0d2fc9 Not spam: http://mail-gw.cognex.com/canit/b.php?c=n&i=7375907&m=aef34f0d2fc9 Forget vote: http://mail-gw.cognex.com/canit/b.php?c=f&i=7375907&m=aef34f0d2fc9 ------------------------------------------------------ END-ANTISPAM-VOTING-LINKS =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com