Re: How to overload == for System.Double
Sébastien Lorion <[email protected]> Fri, 2 Feb 2007 11:44:04 -0500
| Newsgroups | gmane.comp.windows.devel.dotnet.cx |
|---|---|
| Message-ID | <[email protected]> |
I am curious why you do not like extension methods. One can abuse of this feature quite easily, but that is true for about any other language features... Any reason in particular ? Sébastien www.sebastienlorion.com On 2/1/07, Peter Ritchie <[email protected]> wrote: > I was under the impression that the scope of extension methods did not > include extending operators. The C# 3.0 spec. provides no detail for this > either way. > > If it does, that's nother reason not to like extension methods.... > > On Thu, 1 Feb 2007 16:21:11 -0500, Shawn Wildermuth > <[email protected]> wrote: > > ><sarcasm> > > You should be able to do this with C# 3.0 Extension Methods (or > whatever > >they are called). Of course, it's an impossibly bad idea so don't > try...but > >luckily we'll be able to do it soon. > ></sarcasm> > > > > > >Thanks, > > > >Shawn Wildermuth > >Wildermuth Consulting Services, LLC > >http://wildermuthconsulting.com > >http://adoguy.com > >Microsoft MVP (C#), MCSD.NET, Author and Speaker > > > >-----Original Message----- > >From: Discussion relating to the specifics of the C# and Managed C++ > >languages [mailto:[email protected]] On Behalf Of Eames, > Andrew > >Sent: Thursday, February 01, 2007 4:00 PM > >To: [email protected] > >Subject: Re: [DOTNET-CX] How to overload == for System.Double > > > > 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. > > =================================== > This list is hosted by DevelopMentor(r) http://www.develop.com > > View archives and manage your subscription(s) at http://discuss.develop.com > -- Sébastien www.sebastienlorion.com