From e3961197f3f8b7d23ef1d97de14b354d363abda7 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Wed, 28 Jan 2026 14:01:35 -0800 Subject: [PATCH] fix: address fmath.h warning with ispow2 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 --- src/include/OpenImageIO/fmath.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/include/OpenImageIO/fmath.h b/src/include/OpenImageIO/fmath.h index bb73ff14ea..ea31eb43ce 100644 --- a/src/include/OpenImageIO/fmath.h +++ b/src/include/OpenImageIO/fmath.h @@ -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< x-1 is // all 1 bits for bits < b. - return (x & (x - 1)) == 0 && (x >= 0); + if constexpr (std::is_signed::value) { + return (x & (x - 1)) == 0 && (x >= 0); + } else { + return (x & (x - 1)) == 0; + } }