Rollup merge of #89351 - tspiteri:wrapping_rem, r=dtolnay
for signed wrapping remainder, do not compare lhs with MIN Since the wrapped remainder is going to be 0 for all cases when the rhs is -1, there is no need to compare the lhs with MIN.
This commit is contained in:
commit
e745e098c4
1 changed files with 4 additions and 6 deletions
|
@ -1533,9 +1533,8 @@ macro_rules! int_impl {
|
||||||
#[must_use = "this returns the result of the operation, \
|
#[must_use = "this returns the result of the operation, \
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
|
pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
|
||||||
// Using `&` helps LLVM see that it is the same check made in division.
|
if unlikely!(rhs == -1) {
|
||||||
if unlikely!((self == Self::MIN) & (rhs == -1)) {
|
(0, self == Self::MIN)
|
||||||
(0, true)
|
|
||||||
} else {
|
} else {
|
||||||
(self % rhs, false)
|
(self % rhs, false)
|
||||||
}
|
}
|
||||||
|
@ -1565,9 +1564,8 @@ macro_rules! int_impl {
|
||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) {
|
pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) {
|
||||||
// Using `&` helps LLVM see that it is the same check made in division.
|
if unlikely!(rhs == -1) {
|
||||||
if unlikely!((self == Self::MIN) & (rhs == -1)) {
|
(0, self == Self::MIN)
|
||||||
(0, true)
|
|
||||||
} else {
|
} else {
|
||||||
(self.rem_euclid(rhs), false)
|
(self.rem_euclid(rhs), false)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue