Skip to content

Commit 3790d24

Browse files
jdeguiregithub-actions[bot]
authored andcommitted
Automerge: [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().
2 parents a027455 + f76254d commit 3790d24

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libc/src/__support/FPUtil/dyadic_float.h

Lines changed: 6 additions & 1 deletion
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)