maths: add log2up
This commit is contained in:
parent
b3e72051d6
commit
bb3cbb584c
12
maths.cpp
12
maths.cpp
@ -40,6 +40,18 @@ template bool is_pow2 (uint32_t);
|
||||
template bool is_pow2 (uint64_t);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
T
|
||||
log2up (T v)
|
||||
{
|
||||
return log2 ((v << 1) - 1);
|
||||
}
|
||||
|
||||
template uint32_t log2up (uint32_t);
|
||||
template uint64_t log2up (uint64_t);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
T
|
||||
|
@ -41,6 +41,11 @@ T
|
||||
log2 (T val) pure;
|
||||
|
||||
|
||||
template <typename T>
|
||||
T
|
||||
log2up (T val) pure;
|
||||
|
||||
|
||||
template <typename T>
|
||||
double
|
||||
rootsquare (T a, T b) pure;
|
||||
|
@ -45,5 +45,10 @@ main (int, char **) {
|
||||
CHECK_EQ (log2 (8u), 3);
|
||||
CHECK_EQ (log2 (1u), 0);
|
||||
|
||||
CHECK_EQ (log2 (9u), 3);
|
||||
CHECK_EQ (log2up (9u), 4);
|
||||
CHECK_EQ (log2up (8u), 3);
|
||||
CHECK_EQ (log2up (1u), 0);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user