From 61ed85b032b30028b8c1a2fd76905df2982f6db5 Mon Sep 17 00:00:00 2001 From: Ian Clester Date: Sat, 10 Sep 2022 12:52:21 -0400 Subject: [PATCH 1/3] 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; } From 24c921425c617ae7cbbb146456ee64b9e103bb7a Mon Sep 17 00:00:00 2001 From: Ian Clester Date: Sat, 10 Sep 2022 13:13:39 -0400 Subject: [PATCH 2/3] Add another case to formatting test. --- agb-fixnum/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/agb-fixnum/src/lib.rs b/agb-fixnum/src/lib.rs index 355b6007..1d3013d1 100644 --- a/agb-fixnum/src/lib.rs +++ b/agb-fixnum/src/lib.rs @@ -1033,15 +1033,17 @@ mod tests { #[test] fn formats_fractions_correctly() { let a = Num::::new(5); - let two = Num::::new(4); + let four = Num::::new(4); let minus_one = Num::::new(-1); - let b: Num = a / two; + let b: Num = a / four; let c: Num = b * minus_one; + let d: Num = minus_one / four; assert_eq!(b + c, 0.into()); assert_eq!(format!("{}", b), "1.25"); assert_eq!(format!("{}", c), "-1.25"); + assert_eq!(format!("{}", d), "-0.25"); } #[test] From 67a34721aa9111822615d012069d8ebbde388669 Mon Sep 17 00:00:00 2001 From: Ian Clester Date: Sat, 10 Sep 2022 14:37:42 -0400 Subject: [PATCH 3/3] Update changelog. --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43e748b6..a36559d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Fixed - Fixed the fast magnitude function in agb_fixnum. This is also used in fast_normalise. Previously only worked for positive (x, y). +- Fixed formatting of fixed point numbers in the range (-1, 0), which previously appeared positive. ## [0.11.1] - 2022/08/02 @@ -64,4 +65,4 @@ Version 0.10.0 brings about many new features. As with most `agb` upgrades, you ### Fixed - Sprite data is now correctly aligned so fast copies will always work - A few methods which should really be internal have had `pub` removed -- The crate now compiles (but does not run) doctests in CI which pointed out a large number of non-compiling examples \ No newline at end of file +- The crate now compiles (but does not run) doctests in CI which pointed out a large number of non-compiling examples