summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bit.h3
-rw-r--r--tests/bit.c1
2 files changed, 2 insertions, 2 deletions
diff --git a/src/bit.h b/src/bit.h
index e680fed..21a8076 100644
--- a/src/bit.h
+++ b/src/bit.h
@@ -350,8 +350,7 @@ UINT_OVERLOADS(FIRST_TRAILING_ONE)
#define HAS_SINGLE_BIT(type, suffix, width) \
static inline bool has_single_bit##suffix(type n) { \
- /** Branchless n && !(n & (n - 1)) */ \
- return n < (n ^ (n - 1)) + 1; \
+ return n && !(n & (n - 1)); \
}
UINT_OVERLOADS(ROTATE_LEFT)
diff --git a/tests/bit.c b/tests/bit.c
index 7b20770..f9071be 100644
--- a/tests/bit.c
+++ b/tests/bit.c
@@ -119,6 +119,7 @@ int main(void) {
bfs_verify(!has_single_bit(0));
bfs_verify(!has_single_bit(UINT32_MAX));
+ bfs_verify(has_single_bit((uint32_t)1 << (UINT_WIDTH - 1)));
return EXIT_SUCCESS;
}