PC Review


Reply
Thread Tools Rate Thread

C# exponentiation operator & operator overloading

 
 
David Laub
Guest
Posts: n/a
 
      20th Dec 2003
I know there is no C# exponentiation operator. But since
the double class is sealed, there seems no way to add the
operator override without creating a new class which uses
containment (of a double value) This seems a major pain,
and would probably wind up being more syntactically messy
than just calling Math.Pow(x,y)

Surely greater minds than I have already wrestled with
this problem...

David Laub
 
Reply With Quote
 
 
 
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      20th Dec 2003
David,
Just out of curiosity, what operator would you propose to use that would
signify exponentiation?

As all the operators that you are allowed to override already have
predefined meanings. If you attempted to hi-jack one of them, would you not
be introducing semantically messy code? (Am I doing exponentiation here or
am I doing an Xor?)

Remember the "Design Guidelines for Class Library Developers" state "Use
operator overloading in cases where it is immediately obvious what the
result of the operation will be. ... However, it is not appropriate to use
the 'or' operator to create the union of two database queries, or to use
'shift' to write to a stream" Which IMHO avoids semantically messy code.

http://msdn.microsoft.com/library/de...Guidelines.asp

Seeing as semantically messy code tends to be harder for the initial
developer and subsequent developers to follow I don't see a big problem with
using Math.Pow. Of course if you are use to VB.NET or other languages that
have a defined exponentiation operator, I can understand your desire on
mimicking the other language, however C# is NOT the other language!

Hope this helps
Jay

"David Laub" <(E-Mail Removed)> wrote in message
news:004a01c3c733$563be050$(E-Mail Removed)...
> I know there is no C# exponentiation operator. But since
> the double class is sealed, there seems no way to add the
> operator override without creating a new class which uses
> containment (of a double value) This seems a major pain,
> and would probably wind up being more syntactically messy
> than just calling Math.Pow(x,y)
>
> Surely greater minds than I have already wrestled with
> this problem...
>
> David Laub



 
Reply With Quote
 
David Laub
Guest
Posts: n/a
 
      20th Dec 2003




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
about operator overloading Tony Johansson Microsoft C# .NET 1 12th Jun 2008 02:55 PM
Operator Overloading? JP Wrye Microsoft C# .NET 4 10th Sep 2004 07:47 AM
Overloading Operator+ Pranav Shah Microsoft C# .NET 7 23rd Sep 2003 09:24 PM
operator overloading ! lakshmi Microsoft C# .NET 0 19th Sep 2003 05:58 PM
Re: operator overloading ! Frank Oquendo Microsoft C# .NET 0 19th Sep 2003 05:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:36 AM.