How to overload == for System.Double
Jack Brown <[email protected]> Thu, 1 Feb 2007 12:33:08 -0800
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <1367B16B94997E418CDDC01D1BDEF179F0838D@ei-postal.EI.Electroimpact.com> |
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Ā® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com