Two wrappers which help controlling behavior of overflow are Wrapping and Saturating.
This is general request, personally I need only small part of it. Currently, I have to reimplement LCM manually:
impl Count {
pub(crate) fn lcm_saturating(self, other: Self) -> Self {
if self == Self::ZERO || other == Self::ZERO {
return Self::ZERO;
}
let gcd = num_integer::gcd(self.0, other.0);
match (self.0 / gcd).checked_mul(other.0) {
Some(lcm) => Self(lcm),
None => Self::MAX,
}
}
}
When instead it could've been a thin wrapper around num_integer call:
impl Count {
pub(crate) fn lcm_saturating(self, other: Self) -> Self {
Count(num_integer::lcm(Saturating(self.0), Saturating(other.0)).0)
}
}
Two wrappers which help controlling behavior of overflow are
WrappingandSaturating.This is general request, personally I need only small part of it. Currently, I have to reimplement LCM manually:
When instead it could've been a thin wrapper around
num_integercall: