Fix formatting of fixnums in the range (-1, 0)

This commit is contained in:
Ian Clester 2022-09-10 12:52:21 -04:00
parent ed218102ab
commit 61ed85b032

View file

@ -537,6 +537,11 @@ impl<I: FixedWidthUnsignedInteger, const N: usize> Display for Num<I, N> {
// 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();
if integral == I::zero() {
// If the number is in the range (-1, 0), then we just bumped `integral` from -1 to 0,
// so we need to compensate for the missing negative sign.
write!(f, "-")?;
}
fractional = (I::one() << N) - fractional;
}