Skip to content

Instantly share code, notes, and snippets.

@zerob13
Created August 7, 2014 13:45
Show Gist options
  • Save zerob13/20f752f7d147dd35d382 to your computer and use it in GitHub Desktop.
Save zerob13/20f752f7d147dd35d382 to your computer and use it in GitHub Desktop.
the powering ladder
function myPower(x, n) {
var y = 1;
while (1) {
t = n % 2;
n = Math.floor(n / 2);
if (t == 1) {
y = y * x;
}
if (n == 0) {
break;
}
x = x * x;
}
return y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment