fix Rem<Inner> for Fixed

https://gitlab.com/tspiteri/fixed/issues/13
This commit is contained in:
Trevor Spiteri 2020-02-12 16:58:21 +01:00
parent f070f5e75a
commit f8d2004c8f
1 changed files with 7 additions and 1 deletions

View File

@ -370,7 +370,13 @@ macro_rules! fixed_arith {
type Output = $Fixed<Frac>;
#[inline]
fn rem(self, rhs: $Inner) -> $Fixed<Frac> {
Self::from_bits(self.to_bits().rem(rhs))
// Any overflow in coverting rhs to $Fixed<Frac> means that |rhs| > |self|,
// and consequently the remainder is self.
let fixed_rhs = match Self::checked_from_num(rhs) {
Some(s) => s,
None => return self,
};
self.rem(fixed_rhs)
}
}