Add util::is_pow2
This commit is contained in:
parent
fa214ed956
commit
d2f35276bf
1 changed files with 8 additions and 1 deletions
|
|
@ -5,8 +5,15 @@
|
|||
namespace psemek::util
|
||||
{
|
||||
|
||||
// log2 rounded down
|
||||
template <typename T>
|
||||
bool is_pow2(T x)
|
||||
{
|
||||
static_assert(std::is_integral_v<T>);
|
||||
|
||||
return (x > 0) && ((x & (x - 1)) == 0);
|
||||
}
|
||||
|
||||
// log2 rounded down
|
||||
template <typename T>
|
||||
T log2(T x)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue