Skip to content

Commit e3cad47

Browse files
committed
Simplify Rem<iN> for BigInt
The input sign is already checked in `uabs`, and we don't care beyond that, so these don't need the `if`-`else` repetition.
1 parent 5dbd691 commit e3cad47

File tree

1 file changed

+6
-30
lines changed

1 file changed

+6
-30
lines changed

src/bigint.rs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,22 +2045,14 @@ impl Rem<i32> for BigInt {
20452045

20462046
#[inline]
20472047
fn rem(self, other: i32) -> BigInt {
2048-
if other >= 0 {
2049-
self % other as u32
2050-
} else {
2051-
self % other.uabs()
2052-
}
2048+
self % other.uabs()
20532049
}
20542050
}
20552051

20562052
impl RemAssign<i32> for BigInt {
20572053
#[inline]
20582054
fn rem_assign(&mut self, other: i32) {
2059-
if other >= 0 {
2060-
*self %= other as u32;
2061-
} else {
2062-
*self %= other.uabs();
2063-
}
2055+
*self %= other.uabs();
20642056
}
20652057
}
20662058

@@ -2082,22 +2074,14 @@ impl Rem<i64> for BigInt {
20822074

20832075
#[inline]
20842076
fn rem(self, other: i64) -> BigInt {
2085-
if other >= 0 {
2086-
self % other as u64
2087-
} else {
2088-
self % other.uabs()
2089-
}
2077+
self % other.uabs()
20902078
}
20912079
}
20922080

20932081
impl RemAssign<i64> for BigInt {
20942082
#[inline]
20952083
fn rem_assign(&mut self, other: i64) {
2096-
if other >= 0 {
2097-
*self %= other as u64;
2098-
} else {
2099-
*self %= other.uabs();
2100-
}
2084+
*self %= other.uabs();
21012085
}
21022086
}
21032087

@@ -2119,22 +2103,14 @@ impl Rem<i128> for BigInt {
21192103

21202104
#[inline]
21212105
fn rem(self, other: i128) -> BigInt {
2122-
if other >= 0 {
2123-
self % other as u128
2124-
} else {
2125-
self % other.uabs()
2126-
}
2106+
self % other.uabs()
21272107
}
21282108
}
21292109

21302110
impl RemAssign<i128> for BigInt {
21312111
#[inline]
21322112
fn rem_assign(&mut self, other: i128) {
2133-
if other >= 0 {
2134-
*self %= other as u128;
2135-
} else {
2136-
*self %= other.uabs();
2137-
}
2113+
*self %= other.uabs();
21382114
}
21392115
}
21402116

0 commit comments

Comments
 (0)