From c5fb915a6d9e149d79f801423d800415aeef6e36 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sat, 12 Oct 2024 10:01:06 -0700 Subject: [PATCH] div_euclid --- fixed_wide/src/fixed.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/fixed_wide/src/fixed.rs b/fixed_wide/src/fixed.rs index d970585..58aae16 100644 --- a/fixed_wide/src/fixed.rs +++ b/fixed_wide/src/fixed.rs @@ -412,7 +412,7 @@ macro_rules! impl_multiply_operator_not_const_generic { type Output=Self; #[inline] fn divide(self, other: i64)->Self::Output{ - Self::from_bits(self.bits/BInt::from(other)) + Self::from_bits(self.bits.div_euclid(BInt::from(other))) } } } @@ -422,11 +422,11 @@ macro_rules! impl_divide_operator_not_const_generic { impl $struct<$width,F>{ paste::item!{ #[inline] - pub fn [](self, other: Self) -> Self { + pub fn [](self,other:Self)->Self{ //this only needs to be $width+F as u32/64+1 but MUH CONST GENERICS!!!!! let lhs=self.bits.as_::>().shl(F as u32); let rhs=other.bits.as_::>(); - Self::from_bits(lhs.div(rhs).as_()) + Self::from_bits(lhs.div_euclid(rhs).as_()) } } } @@ -446,28 +446,28 @@ macro_rules! impl_divide_operator_not_const_generic { } macro_rules! impl_multiplicative_operator { - ( $struct: ident, $trait: ident, $method: ident, $output: ty ) => { + ( $struct: ident, $trait: ident, $method: ident, $inner_method: ident, $output: ty ) => { impl core::ops::$trait for $struct where BInt:::From+core::ops::$trait, { type Output = $output; #[inline] - fn $method(self, other: U) -> Self::Output { - Self::from_bits(self.bits.$method(BInt::::from(other))) + fn $method(self,other:U)->Self::Output{ + Self::from_bits(self.bits.$inner_method(BInt::::from(other))) } } }; } macro_rules! impl_multiplicative_assign_operator { - ( $struct: ident, $trait: ident, $method: ident ) => { + ( $struct: ident, $trait: ident, $method: ident, $not_assign_method: ident ) => { impl core::ops::$trait for $struct where BInt:::From+core::ops::$trait, { #[inline] - fn $method(&mut self, other: U) { - self.bits.$method(BInt::::from(other)); + fn $method(&mut self,other:U){ + self.bits=self.bits.$not_assign_method(BInt::::from(other)); } } }; @@ -495,10 +495,10 @@ macro_16!( impl_multiplicative_assign_operator_not_const_generic, (Fixed, MulAss macro_16!( impl_multiply_operator_not_const_generic, (Fixed, Mul, mul, Self) ); macro_16!( impl_multiplicative_assign_operator_not_const_generic, (Fixed, DivAssign, div_assign, div) ); macro_16!( impl_divide_operator_not_const_generic, (Fixed, Div, div, Self) ); -impl_multiplicative_assign_operator!( Fixed, MulAssign, mul_assign ); -impl_multiplicative_operator!( Fixed, Mul, mul, Self ); -impl_multiplicative_assign_operator!( Fixed, DivAssign, div_assign ); -impl_multiplicative_operator!( Fixed, Div, div, Self ); +impl_multiplicative_assign_operator!( Fixed, MulAssign, mul_assign, mul ); +impl_multiplicative_operator!( Fixed, Mul, mul, mul, Self ); +impl_multiplicative_assign_operator!( Fixed, DivAssign, div_assign, div_euclid ); +impl_multiplicative_operator!( Fixed, Div, div, div_euclid, Self ); #[cfg(feature="deferred-division")] impl core::ops::Div> for Fixed{ type Output=ratio_ops::ratio::Ratio,Fixed>;