Skip to content

Commit f76254d

Browse files
authored
[libc] Fix implicit conversion error in DyadicFloat::as_mantissa_type(). (#133383)
This is the same fix that was recently applied to as_mantissa_type_rounded(), but for as_mantissa_type().
1 parent 7f103ad commit f76254d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libc/src/__support/FPUtil/dyadic_float.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,12 @@ template <size_t Bits> struct DyadicFloat {
434434
if (exponent > 0) {
435435
new_mant <<= exponent;
436436
} else {
437-
new_mant >>= (-exponent);
437+
// Cast the exponent to size_t before negating it, rather than after,
438+
// to avoid undefined behavior negating INT_MIN as an integer (although
439+
// exponents coming in to this function _shouldn't_ be that large). The
440+
// result should always end up as a positive size_t.
441+
size_t shift = -static_cast<size_t>(exponent);
442+
new_mant >>= shift;
438443
}
439444

440445
if (sign.is_neg()) {

0 commit comments

Comments
 (0)