#pragma once #include #include "defs.h" using namespace std; template constexpr static T clearLowestBit(T value) { return value & (value - 1); } template constexpr static bool ispow2(T value) { return clearLowestBit(value) == 0; } template constexpr static T ceil2(T value) { T value2 = clearLowestBit(value); if (value2 == 0) return value; while (true) { value = value2; value2 = clearLowestBit(value); if (value2 == 0) return value << 1; } } template constexpr static T ipow(T base, T ex) { T x = 1, y = base; while (ex > 0) { if ((ex & 1) == 1) x *= y; y *= y; ex >>= 1; } return x; }