Skip to content

Instantly share code, notes, and snippets.

@tafo
Created July 29, 2020 13:55
Show Gist options
  • Save tafo/1c9b19262358786fef50079aa53c9b51 to your computer and use it in GitHub Desktop.
Save tafo/1c9b19262358786fef50079aa53c9b51 to your computer and use it in GitHub Desktop.
namespace Mathematics.Code
{
public class Number
{
public static double Power(double x, double y)
{
var result = 1.0;
var p = (int)y;
while (p != 0)
{
if ((p & 1) == 1)
{
result *= x;
}
p /= 2;
x *= x;
}
return y < 0 ? 1 / result : result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment