Created
September 21, 2018 14:02
-
-
Save patrickgalbraith/92df3a41cf657989e320149498d7ce63 to your computer and use it in GitHub Desktop.
UInt32 Power Function
This file contains 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
uint UIntPow(uint x, uint pow) | |
{ | |
if (x == 0 || x == 1) | |
return x; | |
if (pow >= 32) | |
throw new OverflowException("Power exceeds allowed size for UInt32"); | |
uint ret = 1; | |
while (pow != 0) | |
{ | |
if ((pow & 1) == 1) | |
ret *= x; | |
x *= x; | |
pow >>= 1; | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment