Wrong remainder with fixed-point LHS and integer RHS
a % b
should be a − trunc(a / b) × b.
If
a = 2−fn,
then
a % b
= 2−fn − trunc(2−fn / b) × b
= 2−f (n − trunc(n / 2f b) × 2fb).
This can be implemented as something similar to Fixed::<Frac>::from_bits(a.to_bits() % (b << Frac))
.
Wrongly, the current implementations is Fixed::<Frac>::from_bits(a.to_bits() % b)
.
This affects all remainder operations with fixed-point LHS and integer RHS, e.g. Rem<i32> for FixedI32
, checked_rem_int
, rem_euclid_int
.
Edited by Trevor Spiteri