Simplify saturating_div
This commit is contained in:
parent
5ca6993307
commit
2b5970f993
@ -946,14 +946,9 @@ macro_rules! int_impl {
|
|||||||
without modifying the original"]
|
without modifying the original"]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn saturating_div(self, rhs: Self) -> Self {
|
pub const fn saturating_div(self, rhs: Self) -> Self {
|
||||||
let (result, overflowed) = self.overflowing_div(rhs);
|
match self.overflowing_div(rhs) {
|
||||||
|
(result, false) => result,
|
||||||
if !overflowed {
|
(_result, true) => Self::MAX, // MIN / -1 is the only possible saturating overflow
|
||||||
result
|
|
||||||
} else if (self < 0) == (rhs < 0) {
|
|
||||||
Self::MAX
|
|
||||||
} else {
|
|
||||||
Self::MIN
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user