fixed_bigint/fixeduint/
num_integer_impl.rsuse super::{FixedUInt, MachineWord};
use num_traits::{One, PrimInt, Zero};
impl<T: MachineWord, const N: usize> num_integer::Integer for FixedUInt<T, N> {
fn div_floor(&self, other: &Self) -> Self {
*self / *other
}
fn mod_floor(&self, other: &Self) -> Self {
*self % *other
}
fn gcd(&self, other: &Self) -> Self {
let mut m = *self;
let mut n = *other;
let zero = Self::zero();
if m == zero || n == zero {
return m | n;
}
let shift = (m | n).trailing_zeros();
m = m >> m.trailing_zeros();
n = n >> n.trailing_zeros();
while m != n {
if m > n {
m -= n;
m = m >> m.trailing_zeros();
} else {
n -= m;
n = n >> n.trailing_zeros();
}
}
m << shift
}
fn lcm(&self, other: &Self) -> Self {
if self.is_zero() && other.is_zero() {
return Self::zero();
}
let gcd = self.gcd(other);
*self * (*other / gcd)
}
fn divides(&self, other: &Self) -> bool {
self.is_multiple_of(other)
}
fn is_multiple_of(&self, other: &Self) -> bool {
(*self) % other == Self::zero()
}
fn is_even(&self) -> bool {
(*self) & Self::one() == Self::zero()
}
fn is_odd(&self) -> bool {
!self.is_even()
}
fn div_rem(&self, other: &Self) -> (Self, Self) {
self.div_rem(other)
}
}