From 61ed85b032b30028b8c1a2fd76905df2982f6db5 Mon Sep 17 00:00:00 2001 From: Ian Clester Date: Sat, 10 Sep 2022 12:52:21 -0400 Subject: [PATCH] Fix formatting of fixnums in the range (-1, 0) --- agb-fixnum/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/agb-fixnum/src/lib.rs b/agb-fixnum/src/lib.rs index 47036f28..355b6007 100644 --- a/agb-fixnum/src/lib.rs +++ b/agb-fixnum/src/lib.rs @@ -537,6 +537,11 @@ impl Display for Num { // 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; }