[go: up one dir, main page]

Wrong remainder with fixed-point LHS and integer RHS

a % b should be a − trunc(a / b) × b.

If a = 2fn, then a % b = 2fn − trunc(2fn / b) × b = 2f (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