diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-05-26 00:47:54 +0200 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-05-26 00:48:06 +0200 |
commit | a1db1cd9e22e77041d5f1360f1d1ccdc52b86306 (patch) | |
tree | c1cc6dc9c17885a0789028f7a55c7126f33beee7 /asl/base/numeric.hpp | |
parent | 54b95b16629f0cd4bc30e6899e00019b3ab94012 (diff) |
Implement chunked_buffer
Diffstat (limited to 'asl/base/numeric.hpp')
-rw-r--r-- | asl/base/numeric.hpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/asl/base/numeric.hpp b/asl/base/numeric.hpp index bbd229d..8d3b8ef 100644 --- a/asl/base/numeric.hpp +++ b/asl/base/numeric.hpp @@ -7,6 +7,7 @@ #include "asl/base/integers.hpp" #include "asl/base/bit.hpp" #include "asl/base/meta.hpp" +#include "asl/base/assert.hpp" namespace asl { @@ -14,10 +15,24 @@ namespace asl template<is_integer T> constexpr bool is_pow2(T x) { - using unsigned_type = select_t<is_unsigned_integer<T>, T, as_unsigned_integer<T>>; + using unsigned_type = as_unsigned_integer<T>; return x > 0 && has_single_bit(static_cast<unsigned_type>(x)); } +template<is_integer T> +constexpr T round_down_pow2(T x, T div) +{ + ASL_ASSERT(is_pow2(div)); + return x & (-div); +} + +template<is_integer T> +constexpr T round_up_pow2(T x, T div) +{ + ASL_ASSERT(is_pow2(div)); + return (x + (div - 1)) & (-div); +} + template<typename T> concept is_numeric = is_integer<T> || is_floating_point<T>; |