We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5ca6993 commit 2b5970fCopy full SHA for 2b5970f
library/core/src/num/int_macros.rs
@@ -946,14 +946,9 @@ macro_rules! int_impl {
946
without modifying the original"]
947
#[inline]
948
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
+ match self.overflowing_div(rhs) {
+ (result, false) => result,
+ (_result, true) => Self::MAX, // MIN / -1 is the only possible saturating overflow
957
}
958
959
0 commit comments