How does one raise an integer to a power?

Discussion in 'ASP .Net' started by Steve Kershaw, Jul 11, 2006.

  1. This is stupid!!!!

    I have looked everywhere (in books, google, online....) to find out how
    to raise a number to a power and I can't find it!!!

    For example:

    given x = 10
    y = x ^ 2;
    y would then be 100 (10 squared is 100).

    Why can't I find such a basic operation!?

    Steve
     
    Steve Kershaw, Jul 11, 2006
    #1
    1. Advertising

  2. Sorry,

    I need this in C#

    Steve


    Steve Kershaw wrote:
    > This is stupid!!!!
    >
    > I have looked everywhere (in books, google, online....) to find out how
    > to raise a number to a power and I can't find it!!!
    >
    > For example:
    >
    > given x = 10
    > y = x ^ 2;
    > y would then be 100 (10 squared is 100).
    >
    > Why can't I find such a basic operation!?
    >
    > Steve
     
    Steve Kershaw, Jul 11, 2006
    #2
    1. Advertising

  3. Math.Pow(x, y)

    --
    Manohar Kamath
    Editor, .netBooks
    www.dotnetbooks.com


    "Steve Kershaw" <> wrote in message
    news:...
    > This is stupid!!!!
    >
    > I have looked everywhere (in books, google, online....) to find out how
    > to raise a number to a power and I can't find it!!!
    >
    > For example:
    >
    > given x = 10
    > y = x ^ 2;
    > y would then be 100 (10 squared is 100).
    >
    > Why can't I find such a basic operation!?
    >
    > Steve
    >
     
    Manohar Kamath, Jul 11, 2006
    #3
  4. It might be useful to point out that the x stands for the number
    to be raised and that the y stands for the power to which the x is raised.

    i.e., the return value of Math.Pow(x, y) is the number x raised to the power y.

    http://msdn2.microsoft.com/en-us/library/system.math.pow.aspx



    Juan T. Llibre, asp.net MVP
    aspnetfaq.com : http://www.aspnetfaq.com/
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en espaƱol : http://asp.net.do/foros/
    ===================================
    "Manohar Kamath" <> wrote in message
    news:%...
    > Math.Pow(x, y)
    >
    > --
    > Manohar Kamath
    > Editor, .netBooks
    > www.dotnetbooks.com
    >
    >
    > "Steve Kershaw" <> wrote in message
    > news:...
    >> This is stupid!!!!
    >>
    >> I have looked everywhere (in books, google, online....) to find out how
    >> to raise a number to a power and I can't find it!!!
    >>
    >> For example:
    >>
    >> given x = 10
    >> y = x ^ 2;
    >> y would then be 100 (10 squared is 100).
    >>
    >> Why can't I find such a basic operation!?
    >>
    >> Steve
    >>

    >
    >
     
    Juan T. Llibre, Jul 11, 2006
    #4
  5. Unlike VB, C# has no exponentiation operator built into the language. You
    have to use the Math class (Math.Pow).
    --
    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB to C# converter
    Instant VB: C# to VB converter
    Instant C++: C#/VB to C++ converter
    C# Code Metrics: Quick metrics for C#


    "Steve Kershaw" wrote:

    > This is stupid!!!!
    >
    > I have looked everywhere (in books, google, online....) to find out how
    > to raise a number to a power and I can't find it!!!
    >
    > For example:
    >
    > given x = 10
    > y = x ^ 2;
    > y would then be 100 (10 squared is 100).
    >
    > Why can't I find such a basic operation!?
    >
    > Steve
    >
    >
     
    =?Utf-8?B?RGF2aWQgQW50b24=?=, Jul 11, 2006
    #5
  6. Steve Kershaw

    clintonG Guest

    Which is where it should be.

    <%= Clinton Gallagher
    NET csgallagher AT metromilwaukee.com
    URL http://www.metromilwaukee.com/clintongallagher/


    "David Anton" <> wrote in message
    news:...
    > Unlike VB, C# has no exponentiation operator built into the language. You
    > have to use the Math class (Math.Pow).
    > --
    > David Anton
    > www.tangiblesoftwaresolutions.com
    > Instant C#: VB to C# converter
    > Instant VB: C# to VB converter
    > Instant C++: C#/VB to C++ converter
    > C# Code Metrics: Quick metrics for C#
    >
    >
    > "Steve Kershaw" wrote:
    >
    >> This is stupid!!!!
    >>
    >> I have looked everywhere (in books, google, online....) to find out how
    >> to raise a number to a power and I can't find it!!!
    >>
    >> For example:
    >>
    >> given x = 10
    >> y = x ^ 2;
    >> y would then be 100 (10 squared is 100).
    >>
    >> Why can't I find such a basic operation!?
    >>
    >> Steve
    >>
    >>
     
    clintonG, Jul 12, 2006
    #6
  7. Using that same argument you could say that we should also have Logical.Or
    instead of || and Math.Multiply instead of *. It's debatable what should be
    built in operators and what shouldn't.
    --
    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB to C# converter
    Instant VB: C# to VB converter
    Instant C++: C#/VB to C++ converter
    C# Code Metrics: Quick metrics for C#


    "clintonG" wrote:

    > Which is where it should be.
    >
    > <%= Clinton Gallagher
    > NET csgallagher AT metromilwaukee.com
    > URL http://www.metromilwaukee.com/clintongallagher/
    >
    >
    > "David Anton" <> wrote in message
    > news:...
    > > Unlike VB, C# has no exponentiation operator built into the language. You
    > > have to use the Math class (Math.Pow).
    > > --
    > > David Anton
    > > www.tangiblesoftwaresolutions.com
    > > Instant C#: VB to C# converter
    > > Instant VB: C# to VB converter
    > > Instant C++: C#/VB to C++ converter
    > > C# Code Metrics: Quick metrics for C#
    > >
    > >
    > > "Steve Kershaw" wrote:
    > >
    > >> This is stupid!!!!
    > >>
    > >> I have looked everywhere (in books, google, online....) to find out how
    > >> to raise a number to a power and I can't find it!!!
    > >>
    > >> For example:
    > >>
    > >> given x = 10
    > >> y = x ^ 2;
    > >> y would then be 100 (10 squared is 100).
    > >>
    > >> Why can't I find such a basic operation!?
    > >>
    > >> Steve
    > >>
    > >>

    >
    >
    >
     
    =?Utf-8?B?RGF2aWQgQW50b24=?=, Jul 14, 2006
    #7
  8. Steve Kershaw

    Michael sJR

    Joined:
    Oct 26, 2012
    Messages:
    2
    Not necessarily... In computer science, powers aren't a basic operation. In fact, they require careful logic and could easily be ineffient. This logic should be placed in a function so software engineers can see the source code and calculate the complexity should they decide to implement a better version.
     
    Michael sJR, Oct 26, 2012
    #8
  9. Steve Kershaw

    Michael sJR

    Joined:
    Oct 26, 2012
    Messages:
    2
    Also, using a function for a basic operation such as or is extremely inefficient because of function call overhead
     
    Michael sJR, Oct 26, 2012
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacol

    raise or not to raise [Newbie]

    Jacol, Feb 3, 2007, in forum: Python
    Replies:
    5
    Views:
    437
    Gabriel Genellina
    Feb 5, 2007
  2. Replies:
    8
    Views:
    395
    Mark Dickinson
    Apr 17, 2008
  3. ernest
    Replies:
    2
    Views:
    311
    Roy Smith
    Nov 14, 2010
  4. Jack Bates
    Replies:
    0
    Views:
    297
    Jack Bates
    May 2, 2011
  5. bvdp

    Raise X or Raise X()?

    bvdp, Mar 11, 2012, in forum: Python
    Replies:
    10
    Views:
    408
    Stefan Behnel
    Mar 12, 2012
Loading...

Share This Page