Add comment explaining how the fiddle works

This commit is contained in:
Gwilym Kuiper 2021-11-18 21:11:29 +00:00
parent 89f89803dd
commit e1e4318c38

View file

@ -459,6 +459,11 @@ impl<I: FixedWidthUnsignedInteger, const N: usize> Display for Num<I, N> {
let mut fractional = self.0 & mask;
// Negative fix nums are awkward to print if they have non zero fractional part.
// This is because you can think of them as `number + non negative fraction`.
//
// But if you think of a negative number, you'd like it to be `negative number - non negative fraction`
// So we have to add 1 to the integral bit, and take 1 - fractional bit
if fractional != I::zero() && integral < I::zero() {
integral = integral + I::one();
fractional = (I::one() << N) - fractional;