diff --git a/fixed_wide/src/fixed.rs b/fixed_wide/src/fixed.rs index 906ce49..26b9d2a 100644 --- a/fixed_wide/src/fixed.rs +++ b/fixed_wide/src/fixed.rs @@ -42,12 +42,14 @@ impl From for Fixed where BInt:From { + #[inline] fn from(value:T)->Self{ Self::from_bits(BInt::<{N}>::from(value)< PartialEq for Fixed{ + #[inline] fn eq(&self,other:&Self)->bool{ self.bits.eq(&other.bits) } @@ -57,6 +59,7 @@ where T:Copy, BInt:::From, { + #[inline] fn eq(&self,&other:&T)->bool{ self.bits.eq(&other.into()) } @@ -64,6 +67,7 @@ where impl Eq for Fixed{} impl PartialOrd for Fixed{ + #[inline] fn partial_cmp(&self,other:&Self)->Option{ self.bits.partial_cmp(&other.bits) } @@ -73,11 +77,13 @@ impl PartialOrd for Fixed T:Copy, BInt:::From, { + #[inline] fn partial_cmp(&self,&other:&T)->Option{ self.bits.partial_cmp(&other.into()) } } impl Ord for Fixed{ + #[inline] fn cmp(&self,other:&Self)->std::cmp::Ordering{ self.bits.cmp(&other.bits) } @@ -85,11 +91,13 @@ impl Ord for Fixed{ impl std::ops::Neg for Fixed{ type Output=Self; + #[inline] fn neg(self)->Self{ Self::from_bits(self.bits.neg()) } } impl std::iter::Sum for Fixed{ + #[inline] fn sum>(iter:I)->Self{ let mut sum=Self::ZERO; for elem in iter{ @@ -109,6 +117,7 @@ macro_rules! impl_additive_operator { } impl core::ops::$trait for $struct{ type Output = $output; + #[inline] fn $method(self, other: Self) -> Self::Output { self.$method(other) } @@ -118,6 +127,7 @@ macro_rules! impl_additive_operator { BInt:::From, { type Output = $output; + #[inline] fn $method(self, other: U) -> Self::Output { Self::from_bits(self.bits.$method(BInt::::from(other).shl(F as u32))) } @@ -127,6 +137,7 @@ macro_rules! impl_additive_operator { macro_rules! impl_additive_assign_operator { ( $struct: ident, $trait: ident, $method: ident ) => { impl core::ops::$trait for $struct{ + #[inline] fn $method(&mut self, other: Self) { self.bits.$method(other.bits); } @@ -135,6 +146,7 @@ macro_rules! impl_additive_assign_operator { where BInt:::From, { + #[inline] fn $method(&mut self, other: U) { self.bits.$method(BInt::::from(other).shl(F as u32)); } @@ -166,6 +178,7 @@ macro_rules! impl_multiplicative_operator_not_const_generic { ( ($struct: ident, $trait: ident, $method: ident, $output: ty ), $width:expr ) => { impl core::ops::$trait for $struct<$width,F>{ type Output = $output; + #[inline] fn $method(self, other: Self) -> Self::Output { paste::item!{ self.[](other) @@ -177,6 +190,7 @@ macro_rules! impl_multiplicative_operator_not_const_generic { macro_rules! impl_multiplicative_assign_operator_not_const_generic { ( ($struct: ident, $trait: ident, $method: ident, $non_assign_method: ident ), $width:expr ) => { impl core::ops::$trait for $struct<$width,F>{ + #[inline] fn $method(&mut self, other: Self) { paste::item!{ *self=self.[](other); @@ -227,7 +241,7 @@ macro_rules! impl_multiplicative_operator { 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))) } @@ -240,6 +254,7 @@ macro_rules! impl_multiplicative_assign_operator { where BInt:::From+core::ops::$trait, { + #[inline] fn $method(&mut self, other: U) { self.bits.$method(BInt::::from(other)); } @@ -276,6 +291,7 @@ impl_multiplicative_operator!( Fixed, Div, div, Self ); #[cfg(feature="deferred-division")] impl core::ops::Div> for Fixed{ type Output=ratio_ops::ratio::Ratio,Fixed>; + #[inline] fn div(self, other: Fixed)->Self::Output{ ratio_ops::ratio::Ratio::new(self,other) } @@ -285,7 +301,7 @@ macro_rules! impl_shift_operator { ( $struct: ident, $trait: ident, $method: ident, $output: ty ) => { impl core::ops::$trait for $struct{ type Output = $output; - + #[inline] fn $method(self, other: u32) -> Self::Output { Self::from_bits(self.bits.$method(other)) } @@ -295,6 +311,7 @@ macro_rules! impl_shift_operator { macro_rules! impl_shift_assign_operator { ( $struct: ident, $trait: ident, $method: ident ) => { impl core::ops::$trait for $struct{ + #[inline] fn $method(&mut self, other: u32) { self.bits.$method(other); } @@ -312,6 +329,7 @@ macro_rules! impl_wide_operators{ ($lhs:expr,$rhs:expr)=>{ impl core::ops::Mul> for Fixed<$lhs,{$lhs*32}>{ type Output=Fixed<{$lhs+$rhs},{($lhs+$rhs)*32}>; + #[inline] fn mul(self, other: Fixed<$rhs,{$rhs*32}>)->Self::Output{ paste::item!{ self.[](other) @@ -321,6 +339,7 @@ macro_rules! impl_wide_operators{ #[cfg(not(feature="deferred-division"))] impl core::ops::Div> for Fixed<$lhs,{$lhs*32}>{ type Output=Fixed<{$lhs+$rhs},{($lhs+$rhs)*32}>; + #[inline] fn div(self, other: Fixed<$rhs,{$rhs*32}>)->Self::Output{ paste::item!{ self.[](other) @@ -341,6 +360,7 @@ macro_rules! impl_wide_not_const_generic{ impl Fixed<$lhs,{$lhs*32}> { paste::item!{ + #[inline] pub fn [](self,rhs:Fixed<$rhs,{$rhs*32}>)->Fixed<{$lhs+$rhs},{($lhs+$rhs)*32}>{ let lhs=self.bits.as_::>(); let rhs=rhs.bits.as_::>(); @@ -349,6 +369,7 @@ macro_rules! impl_wide_not_const_generic{ /// This operation cannot represent the fraction exactly, /// but it shapes the output to have precision for the /// largest and smallest possible fractions. + #[inline] pub fn [](self,rhs:Fixed<$rhs,{$rhs*32}>)->Fixed<{$lhs+$rhs},{($lhs+$rhs)*32}>{ // (lhs/2^LHS_FRAC)/(rhs/2^RHS_FRAC) let lhs=self.bits.as_::>().shl($rhs*64); @@ -382,6 +403,7 @@ macro_repeated!( (1,15) ); impl Fixed{ + #[inline] pub fn resize_into(self)->Fixed{ Fixed::from_bits(self.bits.as_::>()) } @@ -390,12 +412,14 @@ impl Fixed{ macro_rules! impl_not_const_generic{ ($n:expr)=>{ impl Fixed<{$n*2},{$n*2*32}>{ + #[inline] pub fn halve_precision(self)->Fixed<$n,{$n*32}>{ Fixed::from_bits(bnum::cast::As::as_(self.bits.shr($n*32))) } } impl Fixed<$n,{$n*32}>{ paste::item!{ + #[inline] pub fn sqrt_unchecked(self)->Self{ //1<Self{ if selfOption{ if self