How do I calculate power-of in C#?
I'm not that great with maths and C# doesn't seem to provide a power-of function so I was wondering if anyone knows how I would run a calculation like this:
var dimensions = ((100*100) / (100.00^3.00));
See Math.Pow. The function takes a value and raises it to a specified power:
Math.Pow(100.00, 3.00); // 100.00 ^ 3.00
You are looking for the static method Math.Pow()
.
The function you want is Math.Pow
in System.Math
.
Do not use Math.Pow
When i use
for (int i = 0; i < 10e7; i++)
{
var x3 = x * x * x;
var y3 = y * y * y;
}
It only takes 230 ms whereas the following takes incredible 7050 ms:
for (int i = 0; i < 10e7; i++)
{
var x3 = Math.Pow(x, 3);
var y3 = Math.Pow(x, 3);
}