diff options
| author | Michael Watzko <michael@watzko.de> | 2021-08-19 11:28:33 +0200 |
|---|---|---|
| committer | Michael Watzko <michael@watzko.de> | 2021-08-19 11:28:33 +0200 |
| commit | 2b5970f993a091ad51624cdbfefee7dd97f65682 (patch) | |
| tree | 82a2fed33d0408c2c7b6815f4b7535ebac8ab7a8 | |
| parent | 5ca6993307c926f1eb1e536bf957620685b31b00 (diff) | |
| download | rust-2b5970f993a091ad51624cdbfefee7dd97f65682.tar.gz rust-2b5970f993a091ad51624cdbfefee7dd97f65682.zip | |
Simplify saturating_div
| -rw-r--r-- | library/core/src/num/int_macros.rs | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 7c36f4cdd20..2c866812937 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -946,14 +946,9 @@ macro_rules! int_impl { without modifying the original"] #[inline] pub const fn saturating_div(self, rhs: Self) -> Self { - let (result, overflowed) = self.overflowing_div(rhs); - - if !overflowed { - result - } else if (self < 0) == (rhs < 0) { - Self::MAX - } else { - Self::MIN + match self.overflowing_div(rhs) { + (result, false) => result, + (_result, true) => Self::MAX, // MIN / -1 is the only possible saturating overflow } } |
