Skip to content

Commit 292d6da

Browse files
bytegrrrlheinezen
andcommitted
Optimize FixedPoint::sqrt() signedness check
Co-authored-by: Christoph Heine <[email protected]>
1 parent 55196f1 commit 292d6da

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libopenage/util/fixed_point.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,9 @@ class FixedPoint {
464464
}
465465

466466
// Check for negative values
467-
ENSURE(std::is_unsigned<raw_type>() or (std::is_signed<raw_type>() and this->raw_value > 0), "FixedPoint::sqrt() is undefined for negative values.");
467+
if constexpr (std::is_signed<raw_type>()) {
468+
ENSURE(this->raw_value > 0, "FixedPoint::sqrt() is undefined for negative values.");
469+
}
468470

469471
// A greater shift = more precision, but can overflow the intermediate type if too large.
470472
size_t max_shift = std::countl_zero(static_cast<unsigned_intermediate_type>(this->raw_value)) - 1;

0 commit comments

Comments
 (0)