Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use core::ops::{Neg, Not};
use core::str;

use num_integer::{Integer, Roots};
use num_traits::{ConstZero, Num, One, Pow, Signed, Zero};
use num_traits::{CheckedNeg, ConstZero, Num, One, Pow, Signed, Zero};

use self::Sign::{Minus, NoSign, Plus};

Expand Down Expand Up @@ -344,6 +344,13 @@ impl Neg for &BigInt {
}
}

impl CheckedNeg for BigInt {
#[inline]
fn checked_neg(&self) -> Option<BigInt> {
Some(self.neg())
}
}

impl Integer for BigInt {
#[inline]
fn div_rem(&self, other: &BigInt) -> (BigInt, BigInt) {
Expand Down
12 changes: 11 additions & 1 deletion src/bigint/division.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{IsizePromotion, UsizePromotion};

use core::ops::{Div, DivAssign, Rem, RemAssign};
use num_integer::Integer;
use num_traits::{CheckedDiv, CheckedEuclid, Euclid, Signed, ToPrimitive, Zero};
use num_traits::{CheckedDiv, CheckedEuclid, CheckedRem, Euclid, Signed, ToPrimitive, Zero};

forward_all_binop_to_ref_ref!(impl Div for BigInt, div);

Expand Down Expand Up @@ -447,6 +447,16 @@ impl CheckedDiv for BigInt {
}
}

impl CheckedRem for BigInt {
#[inline]
fn checked_rem(&self, v: &BigInt) -> Option<BigInt> {
if v.is_zero() {
return None;
}
Some(self.rem(v))
}
}

impl CheckedEuclid for BigInt {
#[inline]
fn checked_div_euclid(&self, v: &BigInt) -> Option<BigInt> {
Expand Down
12 changes: 11 additions & 1 deletion src/biguint/division.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::cmp::Ordering::{Equal, Greater, Less};
use core::mem;
use core::ops::{Div, DivAssign, Rem, RemAssign};
use num_integer::Integer;
use num_traits::{CheckedDiv, CheckedEuclid, Euclid, ToPrimitive, Zero};
use num_traits::{CheckedDiv, CheckedEuclid, CheckedRem, Euclid, ToPrimitive, Zero};

pub(super) const FAST_DIV_WIDE: bool = cfg!(any(target_arch = "x86", target_arch = "x86_64"));

Expand Down Expand Up @@ -784,6 +784,16 @@ impl CheckedDiv for BigUint {
}
}

impl CheckedRem for BigUint {
#[inline]
fn checked_rem(&self, v: &BigUint) -> Option<BigUint> {
if v.is_zero() {
return None;
}
Some(self.rem(v))
}
}

impl CheckedEuclid for BigUint {
#[inline]
fn checked_div_euclid(&self, v: &BigUint) -> Option<BigUint> {
Expand Down