^ operator in VB.Net what in C#?

  • Thread starter Thread starter Hiten
  • Start date Start date
H

Hiten

Hi
in VB.Net 3^3 will output 27....
what about in C# if i use 3^3 it gives error? is there is another
operator for it or i have to maually write the code?

thanks
 
no such operator in c#.
use Math.Pow(x, y) instead.

from msdn:
x : A number to be raised to a power.
y : A number that specifies a power.
 
If both operands are integers, maybe it is better to use you own function:

public static long int Power(long int a, int b)
{
long int f = 1;
for (int i = 1; i <= b; i++)
f *= a;
return f;
}

Regards - Octavio
 
Octavio Hernandez said:
If both operands are integers, maybe it is better to use you own function:
public static long int Power(long int a, int b)
{
long int f = 1;
for (int i = 1; i <= b; i++)
f *= a;
return f;
}

Or even just use what's built-in... Math.Pow(a, b)
 
Octavio Hernandez said:
The Math.Pow() method accepts any double operands, so I guess it works by
means of logarithms, etc. which could be slower if the operands are
integers. That's what I meant.

Or both of you could stop pontificating and write a testapp. :)

Using releasemode code the breakeven point for math.Pow was ~30^30.
Smaller pairs were much faster in a for loop, higher ones really showed the
benefit of using logs instead of loops.
 
Thanks, Dan ! I really should have written that test, haven't done any maths
in my applications for some time...

Regards - Octavio
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top