diff --git a/src/arith.rs b/src/arith.rs index b26c986..ca4d9fc 100644 --- a/src/arith.rs +++ b/src/arith.rs @@ -370,7 +370,13 @@ macro_rules! fixed_arith { type Output = $Fixed; #[inline] fn rem(self, rhs: $Inner) -> $Fixed { - Self::from_bits(self.to_bits().rem(rhs)) + // Any overflow in coverting rhs to $Fixed 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) } }