Add util::log2
This commit is contained in:
parent
b97e7bc26c
commit
b243639f8d
1 changed files with 14 additions and 0 deletions
|
|
@ -5,6 +5,20 @@
|
|||
namespace psemek::util
|
||||
{
|
||||
|
||||
// log2 rounded down
|
||||
|
||||
template <typename T>
|
||||
T log2(T x)
|
||||
{
|
||||
T result = 0;
|
||||
while (x > 1)
|
||||
{
|
||||
++result;
|
||||
x /= 2;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// round up to power of 2
|
||||
template <typename T>
|
||||
T round_pow2(T x)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue