We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7f103ad commit f76254dCopy full SHA for f76254d
libc/src/__support/FPUtil/dyadic_float.h
@@ -434,7 +434,12 @@ template <size_t Bits> struct DyadicFloat {
434
if (exponent > 0) {
435
new_mant <<= exponent;
436
} else {
437
- new_mant >>= (-exponent);
+ // 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;
443
}
444
445
if (sign.is_neg()) {
0 commit comments