core: Fix overflow in int::mod_euc when self < 0 && rhs == MIN
This commit is contained in:
@@ -1765,7 +1765,11 @@ assert_eq!((-a).mod_euc(-b), 1);
|
||||
pub fn mod_euc(self, rhs: Self) -> Self {
|
||||
let r = self % rhs;
|
||||
if r < 0 {
|
||||
r + rhs.abs()
|
||||
if rhs.is_negative() {
|
||||
r - rhs
|
||||
} else {
|
||||
r + rhs
|
||||
}
|
||||
} else {
|
||||
r
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user