^ operator in VB.Net what in C#?

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
 
R

realfun

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.
 
O

Octavio Hernandez

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
 
M

Mark Rae

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)
 
G

Guest

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.
 
O

Octavio Hernandez

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

mid in C# 2
AND operator with byte operands 2
"in" operator 1
question regarding C# division modulus 2
Errors computing modulo 7
Question about an old operator 6
VB.NET vs C# OOP. 2
VB.NET Datasets 0

Top