Last active
August 29, 2015 14:16
-
-
Save seantunwin/2f092130c76e4de0c720 to your computer and use it in GitHub Desktop.
Easy power function (like Math.pow()) for positive exponents using the shift-left bitwise operator
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
| // Where @var exponent is less than or equal to 1 | |
| // @return is @var num | |
| function posPow(num, exponent) { | |
| return num << ((exponent > 1) ? (exponent - 1) : 0 ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment