By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,595 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

C# exponentiation operator & operator overloading

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <dl***@prodigy.net> wrote in message
news:00****************************@phx.gbl...
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

Nov 15 '05 #2

P: n/a


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.