Last active
March 29, 2017 01:54
-
-
Save ryanwoodsmall/80d5323ba59c52db2b8417db7cc19322 to your computer and use it in GitHub Desktop.
nasty buggy javascript exponent thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myexpt(x, y) { | |
var expt = 1; | |
if (x < 0) { | |
// XXX - need to check Number.isFinite(parseFloat(y)) and cast for modulus via parseInt | |
if (y % 2 != 0) { | |
expt = -1 * myexpt(Math.abs(x), y); | |
} else { | |
expt = myexpt(Math.abs(x), y); | |
} | |
} else { | |
if (y < 0) { | |
expt = 1 / myexpt(x, Math.abs(y)); | |
} else if (y == 0) { | |
expt = 1; | |
} else if (y > 0) { | |
expt = x * myexpt(x, y - 1); | |
} | |
} | |
return(expt); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment