From 09331d1cb5870fe2a2f8d12389439d372d4bccb4 Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 9 Oct 2023 19:16:24 +0100 Subject: [PATCH] make 16 bit precision work --- agb-fixnum/src/lib.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/agb-fixnum/src/lib.rs b/agb-fixnum/src/lib.rs index ea8d4adf..8b0d1b0c 100644 --- a/agb-fixnum/src/lib.rs +++ b/agb-fixnum/src/lib.rs @@ -133,7 +133,7 @@ macro_rules! upcast_multiply_impl { .wrapping_mul(b_frac) .wrapping_add(b_floor.wrapping_mul(a_frac)), ) - .wrapping_add(a_frac.wrapping_mul(b_frac) >> n) + .wrapping_add(((a_frac as u32).wrapping_mul(b_frac as u32) >> n) as $T) } }; ($T: ty, $Upcast: ty) => { @@ -1236,6 +1236,17 @@ mod tests { ); } + #[test] + fn check_16_bit_precision_i32() { + let a: Num = num!(1.923); + let b = num!(2.723); + + assert_eq!( + a * b, + Num::from_raw(((a.to_raw() as i64 * b.to_raw() as i64) >> 16) as i32) + ) + } + #[test] fn test_numbers() { // test addition