diff options
author | tomsmeding <tom.smeding@gmail.com> | 2019-04-20 19:41:16 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2019-04-20 19:41:16 +0200 |
commit | ccade8e6ed96fb48b329d22aaa4c8d0826b3c8d1 (patch) | |
tree | b9389a557869a38d0cdb9de02247abf1446e5db3 /aberth/util.h | |
parent | dc6f869c48c267e2091d686a66209c4f741d62e4 (diff) |
Move some code out of main.cpp
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); |