Last active
August 29, 2015 14:20
-
-
Save MattiasFestin/6e688fef1174f7bc6fc3 to your computer and use it in GitHub Desktop.
Power modulo (Requires propper tail calls)
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
let modPow = (b, e, m, value = 1) => { | |
b = b % m; | |
if (e % 2 === 1) { | |
value = (value * b) % m; | |
} | |
return e <= 1 ? value : modPow(b * b, e >> 1, m, value); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment