# How does one raise an integer to a power?

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

1. ### Steve KershawGuest

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. ### Steve KershawGuest

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

3. ### Manohar KamathGuest

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
4. ### Juan T. LlibreGuest

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
5. ### =?Utf-8?B?RGF2aWQgQW50b24=?=Guest

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
6. ### clintonGGuest

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
7. ### =?Utf-8?B?RGF2aWQgQW50b24=?=Guest

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
8. ### 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
9. ### 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