maths: add log2
This commit is contained in:
parent
59348c0589
commit
755e0d92cb
20
maths.cpp
20
maths.cpp
@ -40,6 +40,26 @@ template bool is_pow2 (uint32_t);
|
||||
template bool is_pow2 (uint64_t);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
T
|
||||
log2 (T v) {
|
||||
static_assert (std::is_integral<T>::value,
|
||||
"log2 is only implemented for integers");
|
||||
|
||||
T l = 0;
|
||||
while (v) {
|
||||
v >>= 1;
|
||||
l += 1;
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
template uint32_t log2 (uint32_t);
|
||||
template uint64_t log2 (uint64_t);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
double
|
||||
|
Loading…
Reference in New Issue
Block a user