From 8b2f3f14bb0d4a627c6d8265649e84832bd25074 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Sat, 5 Jun 2021 15:46:13 +0100 Subject: [PATCH] Use more precise implementations --- agb/src/number.rs | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/agb/src/number.rs b/agb/src/number.rs index d5229703..14c49e5a 100644 --- a/agb/src/number.rs +++ b/agb/src/number.rs @@ -41,42 +41,26 @@ impl SubAssign for Num { impl Mul for Num { type Output = Self; fn mul(self, rhs: Num) -> Self::Output { - if N % 2 == 0 { - Num((self.0 >> (N / 2)) * (rhs.0 >> (N / 2))) - } else { - Num((self.0 >> (1 + N / 2)) * (rhs.0 >> (N / 2))) - } + Num((self.0 * rhs.0) >> N) } } impl MulAssign for Num { fn mul_assign(&mut self, rhs: Self) { - if N % 2 == 0 { - self.0 = (self.0 >> (N / 2)) * (rhs.0 >> (N / 2)) - } else { - self.0 = (self.0 >> (1 + N / 2)) * (rhs.0 >> (N / 2)) - } + self.0 = (*self * rhs).0 } } impl Div for Num { type Output = Self; fn div(self, rhs: Num) -> Self::Output { - if N % 2 == 0 { - Num((self.0 << (N / 2)) / (rhs.0 >> (N / 2))) - } else { - Num((self.0 << (1 + N / 2)) / (rhs.0 >> (N / 2))) - } + Num((self.0 << N) / rhs.0) } } impl DivAssign for Num { fn div_assign(&mut self, rhs: Self) { - if N % 2 == 0 { - self.0 = (self.0 << (N / 2)) / (rhs.0 >> (N / 2)) - } else { - self.0 = (self.0 << (1 + N / 2)) / (rhs.0 >> (N / 2)) - } + self.0 = (*self / rhs).0 } }