Skip to content

Commit 2b5970f

Browse files
committed
Simplify saturating_div
1 parent 5ca6993 commit 2b5970f

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

library/core/src/num/int_macros.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -946,14 +946,9 @@ macro_rules! int_impl {
946946
without modifying the original"]
947947
#[inline]
948948
pub const fn saturating_div(self, rhs: Self) -> Self {
949-
let (result, overflowed) = self.overflowing_div(rhs);
950-
951-
if !overflowed {
952-
result
953-
} else if (self < 0) == (rhs < 0) {
954-
Self::MAX
955-
} else {
956-
Self::MIN
949+
match self.overflowing_div(rhs) {
950+
(result, false) => result,
951+
(_result, true) => Self::MAX, // MIN / -1 is the only possible saturating overflow
957952
}
958953
}
959954

0 commit comments

Comments
 (0)