From 9cf09165b5f3c536fa8149fffb766605333e2d14 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Fri, 28 Apr 2023 14:42:49 +0300 Subject: [PATCH] BAN: Add is_power_of_two to Math functions --- BAN/include/BAN/Math.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BAN/include/BAN/Math.h b/BAN/include/BAN/Math.h index fa05875d..8302decf 100644 --- a/BAN/include/BAN/Math.h +++ b/BAN/include/BAN/Math.h @@ -51,6 +51,14 @@ namespace BAN::Math return (a + b - 1) / b; } + template + inline constexpr bool is_power_of_two(T value) + { + if (value == 0) + return false; + return (value & (value - 1)) == 0; + } + template inline constexpr T little_endian_to_host(const uint8_t* bytes) {