Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move integer math functions to GeodesicGrid namespace
- Loading branch information
Showing
4 changed files
with
39 additions
and
36 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
| ||
namespace Kethane.GeodesicGrid | ||
{ | ||
internal static class IntMath | ||
{ | ||
// From: http://stackoverflow.com/a/383596/303422 | ||
public static int IntPow(int x, uint pow) | ||
{ | ||
int ret = 1; | ||
while (pow != 0) | ||
{ | ||
if ((pow & 1) == 1) | ||
ret *= x; | ||
x *= x; | ||
pow >>= 1; | ||
} | ||
return ret; | ||
} | ||
|
||
private static int[] MultiplyDeBruijnBitPosition = { | ||
0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, | ||
8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 | ||
}; | ||
|
||
public static int LogBase2(uint v) | ||
{ | ||
v |= v >> 1; | ||
v |= v >> 2; | ||
v |= v >> 4; | ||
v |= v >> 8; | ||
v |= v >> 16; | ||
|
||
return MultiplyDeBruijnBitPosition[(v * 0x7C4ACDDU) >> 27]; | ||
} | ||
} | ||
} |
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
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