C# exponentiation operator & operator overloading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Laub

    #1

    C# exponentiation operator & operator overloading

    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
  • Jay B. Harlow [MVP - Outlook]

    #2
    Re: C# exponentiation operator & operator overloading

    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" <dlaub@prodigy. net> wrote in message
    news:004a01c3c7 33$563be050$a50 1280a@phx.gbl.. .[color=blue]
    > 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[/color]


    Comment

    • David Laub

      #3
      Re: C# exponentiation operator &amp; operator overloading





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

      Comment

      Working...