Skip to content

Commit 9efdb3b

Browse files
committed
Address review nits 2025-01-29
1 parent 045ba35 commit 9efdb3b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

libc/src/__support/FPUtil/dyadic_float.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,23 @@ rounding_direction(const LIBC_NAMESPACE::UInt<Bits> &value, size_t rshift,
5252
// We round up, unless the value is an exact halfway case and
5353
// the bit that will end up in the units place is 0, in which
5454
// case tie-break-to-even says round down.
55-
return value.get_bit(rshift) != 0 || (value << (Bits - rshift + 1)) != 0
56-
? +1
57-
: -1;
55+
bool round_bit = rshift < Bits ? value.get_bit(rshift) : 0;
56+
return round_bit != 0 || (value << (Bits - rshift + 1)) != 0 ? +1 : -1;
5857
} else {
5958
return -1;
6059
}
6160
case FE_TOWARDZERO:
6261
return -1;
6362
case FE_DOWNWARD:
64-
return logical_sign.is_neg() && (value << (Bits - rshift)) != 0 ? +1 : -1;
63+
return logical_sign.is_neg() &&
64+
(rshift < Bits && (value << (Bits - rshift)) != 0)
65+
? +1
66+
: -1;
6567
case FE_UPWARD:
66-
return logical_sign.is_pos() && (value << (Bits - rshift)) != 0 ? +1 : -1;
68+
return logical_sign.is_pos() &&
69+
(rshift < Bits && (value << (Bits - rshift)) != 0)
70+
? +1
71+
: -1;
6772
default:
6873
__builtin_unreachable();
6974
}
@@ -652,9 +657,8 @@ rounded_div(const DyadicFloat<Bits> &af, const DyadicFloat<Bits> &bf) {
652657
}
653658

654659
DyadicFloat<(Bits * 2)> qbig(qf.sign, qf.exponent - 2, q);
655-
auto qfinal = DyadicFloat<Bits>::round(qbig.sign, qbig.exponent + Bits,
656-
qbig.mantissa, Bits);
657-
return qfinal;
660+
return DyadicFloat<Bits>::round(qbig.sign, qbig.exponent + Bits,
661+
qbig.mantissa, Bits);
658662
}
659663

660664
// Simple polynomial approximation.

0 commit comments

Comments
 (0)