diff options
Diffstat (limited to 'aberth/util.h')
-rw-r--r-- | aberth/util.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/aberth/util.h b/aberth/util.h new file mode 100644 index 0000000..c21a7bb --- /dev/null +++ b/aberth/util.h @@ -0,0 +1,31 @@ +#pragma once + +#include <iostream> +#include "defs.h" + +using namespace std; + + +template <typename T> +constexpr static T clearLowestBit(T value) { + return value & (value - 1); +} + +template <typename T> +constexpr static bool ispow2(T value) { + return clearLowestBit(value) == 0; +} + +template <typename T> +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; + } +} + +ostream& operator<<(ostream &os, const Poly &p); |