Skip to content

Commit 0ceac85

Browse files
authored
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>
1 parent e94a270 commit 0ceac85

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/include/OpenImageIO/fmath.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ ispow2(T x) noexcept
144144
// Numerous references for this bit trick are on the web. The
145145
// principle is that x is a power of 2 <=> x == 1<<b <=> x-1 is
146146
// all 1 bits for bits < b.
147-
return (x & (x - 1)) == 0 && (x >= 0);
147+
if constexpr (std::is_signed<T>::value) {
148+
return (x & (x - 1)) == 0 && (x >= 0);
149+
} else {
150+
return (x & (x - 1)) == 0;
151+
}
148152
}
149153

150154

0 commit comments

Comments
 (0)