Skip to content

Commit

Permalink
Merge pull request #301 from cuviper/unsigned_abs
Browse files Browse the repository at this point in the history
Use inherent `unsigned_abs`
  • Loading branch information
cuviper committed May 4, 2024
2 parents 1f92024 + 454b869 commit 636317c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
9 changes: 0 additions & 9 deletions src/bigint.rs
Expand Up @@ -293,10 +293,6 @@ impl Signed for BigInt {
trait UnsignedAbs {
type Unsigned;

/// A convenience method for getting the absolute value of a signed primitive as unsigned
/// See also `unsigned_abs`: <https://github.com/rust-lang/rust/issues/74913>
fn uabs(self) -> Self::Unsigned;

fn checked_uabs(self) -> CheckedUnsignedAbs<Self::Unsigned>;
}

Expand All @@ -311,11 +307,6 @@ macro_rules! impl_unsigned_abs {
impl UnsignedAbs for $Signed {
type Unsigned = $Unsigned;

#[inline]
fn uabs(self) -> $Unsigned {
self.wrapping_abs() as $Unsigned
}

#[inline]
fn checked_uabs(self) -> CheckedUnsignedAbs<Self::Unsigned> {
if self >= 0 {
Expand Down
12 changes: 6 additions & 6 deletions src/bigint/division.rs
Expand Up @@ -358,14 +358,14 @@ impl Rem<i32> for BigInt {

#[inline]
fn rem(self, other: i32) -> BigInt {
self % other.uabs()
self % other.unsigned_abs()
}
}

impl RemAssign<i32> for BigInt {
#[inline]
fn rem_assign(&mut self, other: i32) {
*self %= other.uabs();
*self %= other.unsigned_abs();
}
}

Expand All @@ -386,14 +386,14 @@ impl Rem<i64> for BigInt {

#[inline]
fn rem(self, other: i64) -> BigInt {
self % other.uabs()
self % other.unsigned_abs()
}
}

impl RemAssign<i64> for BigInt {
#[inline]
fn rem_assign(&mut self, other: i64) {
*self %= other.uabs();
*self %= other.unsigned_abs();
}
}

Expand All @@ -414,14 +414,14 @@ impl Rem<i128> for BigInt {

#[inline]
fn rem(self, other: i128) -> BigInt {
self % other.uabs()
self % other.unsigned_abs()
}
}

impl RemAssign<i128> for BigInt {
#[inline]
fn rem_assign(&mut self, other: i128) {
*self %= other.uabs();
*self %= other.unsigned_abs();
}
}

Expand Down

0 comments on commit 636317c

Please sign in to comment.