#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn checked_div(self, other: Self) -> Option<Self> {
- if other == 0 {
+ if other == 0 || (self == Self::min_value() && other == -1) {
None
} else {
- let (a, b) = self.overflowing_div(other);
- if b {None} else {Some(a)}
+ Some(unsafe { intrinsics::unchecked_div(self, other) })
}
}
#[stable(feature = "wrapping", since = "1.7.0")]
#[inline]
pub fn checked_rem(self, other: Self) -> Option<Self> {
- if other == 0 {
+ if other == 0 || (self == Self::min_value() && other == -1) {
None
} else {
- let (a, b) = self.overflowing_rem(other);
- if b {None} else {Some(a)}
+ Some(unsafe { intrinsics::unchecked_rem(self, other) })
}
}
pub fn checked_div(self, other: Self) -> Option<Self> {
match other {
0 => None,
- other => Some(self / other),
+ other => Some(unsafe { intrinsics::unchecked_div(self, other) }),
}
}
if other == 0 {
None
} else {
- Some(self % other)
+ Some(unsafe { intrinsics::unchecked_rem(self, other) })
}
}