Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Raising to a power using an extension method.
public static int Exp(this int x, int y)
{
int result = 1;
while (y > 0)
{
if ((y & 1) != 0)
{
result *= x;
}
y >>= 1;
x *= x;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment