Velocity Reviews > How does one raise an integer to a power?

# How does one raise an integer to a power?

Steve Kershaw
Guest
Posts: n/a

 07-11-2006
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
Guest
Posts: n/a

 07-11-2006
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

Manohar Kamath
Guest
Posts: n/a

 07-11-2006
Math.Pow(x, y)

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

"Steve Kershaw" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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
Guest
Posts: n/a

 07-11-2006
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/lib....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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Math.Pow(x, y)
>
> --
> Manohar Kamath
> Editor, .netBooks
> www.dotnetbooks.com
>
>
> "Steve Kershaw" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
>> 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=?=
Guest
Posts: n/a

 07-11-2006
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
Guest
Posts: n/a

 07-12-2006
Which is where it should be.

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

"David Anton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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=?=
Guest
Posts: n/a

 07-14-2006
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >>
> >>

>
>
>

Michael sJR
Junior Member
Join Date: Oct 2012
Posts: 2

 10-26-2012
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
Junior Member
Join Date: Oct 2012
Posts: 2

 10-26-2012
Also, using a function for a basic operation such as or is extremely inefficient because of function call overhead