(Math) Added CountBits function
Former-commit-id: 11e825a95a7bda300e46eb321f0fdb51bea93343
This commit is contained in:
@@ -114,6 +114,20 @@ constexpr T NzClamp(T value, T min, T max)
|
||||
return std::max(std::min(value, max), min);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NzCountBits(T value)
|
||||
{
|
||||
// https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan
|
||||
unsigned int count = 0;
|
||||
while (value)
|
||||
{
|
||||
value &= value - 1;
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T NzDegreeToRadian(T degrees)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user