fix: address fmath.h warning with ispow2 (#5033)

I was seeing warnings with instantiation of the ispow2 function template
for unsigned type, where the `x >= 0` clause is meaningless. Use a
constexpr if to eliminate that pointless test for unsigned types.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
This commit is contained in:
Larry Gritz
2026-02-23 20:31:49 -08:00
committed by GitHub
parent e94a27004e
commit 0ceac85217
+5 -1
View File
@@ -144,7 +144,11 @@ ispow2(T x) noexcept
// Numerous references for this bit trick are on the web. The
// principle is that x is a power of 2 <=> x == 1<<b <=> x-1 is
// all 1 bits for bits < b.
return (x & (x - 1)) == 0 && (x >= 0);
if constexpr (std::is_signed<T>::value) {
return (x & (x - 1)) == 0 && (x >= 0);
} else {
return (x & (x - 1)) == 0;
}
}