diff --git a/fixed_wide/src/fixed.rs b/fixed_wide/src/fixed.rs index b26a4ed..71b56e3 100644 --- a/fixed_wide/src/fixed.rs +++ b/fixed_wide/src/fixed.rs @@ -1,11 +1,10 @@ use bnum::{BInt,cast::As}; use typenum::Unsigned; -use std::marker::PhantomData; #[derive(Clone,Copy,Debug,Hash)] pub struct Fixed{ pub(crate)bits:BInt<{CHUNKS}>, - pub(crate)frac:PhantomData, + pub(crate)frac:std::marker::PhantomData, } impl Fixed{ @@ -20,10 +19,12 @@ impl Fixed{ pub const NEG_ONE:Self=Self::from_bits(BInt::::NEG_ONE.shl(Frac::U32)); pub const NEG_TWO:Self=Self::from_bits(BInt::::NEG_TWO.shl(Frac::U32)); pub const NEG_HALF:Self=Self::from_bits(BInt::::NEG_ONE.shl(Frac::U32-1)); +} +impl Fixed{ pub const fn from_bits(bits:BInt::)->Self{ Self{ bits, - frac:PhantomData, + frac:std::marker::PhantomData, } } pub const fn to_bits(self)->BInt{ @@ -39,10 +40,7 @@ impl From for Fixed BInt:From { fn from(value:T)->Self{ - Self{ - bits:BInt::<{CHUNKS}>::from(value)<::from(value)< Ord for Fixed{ impl std::ops::Neg for Fixed{ type Output=Self; fn neg(self)->Self{ - Self{ - bits:self.bits.neg(), - frac:PhantomData, - } + Self::from_bits(self.bits.neg()) } } @@ -80,10 +75,7 @@ macro_rules! impl_additive_operator { type Output = $output; fn $method(self, other: Self) -> Self::Output { - Self { - bits:self.bits.$method(other.bits), - frac:PhantomData, - } + Self::from_bits(self.bits.$method(other.bits)) } } impl core::ops::$trait for $struct @@ -93,10 +85,7 @@ macro_rules! impl_additive_operator { type Output = $output; fn $method(self, other: U) -> Self::Output { - Self { - bits:self.bits.$method(BInt::::from(other)<::from(other)<>(); let rhs=other.bits.as_::>(); - Self { - bits:lhs.mul(rhs).shr(Frac::U32).as_(), - frac:PhantomData, - } + Self::from_bits(lhs.mul(rhs).shr(Frac::U32).as_()) } } }; @@ -172,10 +158,7 @@ macro_rules! impl_divide_operator_const { //this only needs to be $width+Frac::U32/64+1 but MUH CONST GENERICS!!!!! let lhs=self.bits.as_::>().shl(Frac::U32); let rhs=other.bits.as_::>(); - Self { - bits:lhs.div(rhs).as_(), - frac:PhantomData, - } + Self::from_bits(lhs.div(rhs).as_()) } } }; @@ -199,10 +182,7 @@ macro_rules! impl_multiplicatave_operator { type Output = $output; fn $method(self, other: U) -> Self::Output { - Self { - bits:self.bits.$method(BInt::::from(other)), - frac:PhantomData, - } + Self::from_bits(self.bits.$method(BInt::::from(other))) } } }; @@ -276,10 +256,7 @@ macro_rules! impl_shift_operator { type Output = $output; fn $method(self, other: u32) -> Self::Output { - Self { - bits:self.bits.$method(other), - frac:PhantomData, - } + Self::from_bits(self.bits.$method(other)) } } }; diff --git a/fixed_wide/src/fixed_wide_traits.rs b/fixed_wide/src/fixed_wide_traits.rs index 185ec95..c48ce71 100644 --- a/fixed_wide/src/fixed_wide_traits.rs +++ b/fixed_wide/src/fixed_wide_traits.rs @@ -3,7 +3,6 @@ use bnum::cast::As; use typenum::{Sum,Unsigned}; use crate::fixed::Fixed; use fixed_wide_traits::wide::WideMul; -use std::marker::PhantomData; macro_rules! impl_wide_mul { ($lhs: expr,$rhs: expr) => { @@ -14,10 +13,7 @@ macro_rules! impl_wide_mul { { type Output=Fixed<{$lhs+$rhs},Sum>; fn wide_mul(self,rhs:Fixed<$rhs,B>)->Self::Output{ - Fixed{ - bits:self.bits.as_::>()*rhs.bits.as_::>(), - frac:PhantomData, - } + Fixed::from_bits(self.bits.as_::>()*rhs.bits.as_::>()) } } }; @@ -44,10 +40,7 @@ impl_wide_mul_all!( ); impl Fixed{ pub fn widen(self)->Fixed{ - Fixed{ - bits:self.bits.as_::>(), - frac:PhantomData, - } + Fixed::from_bits(self.bits.as_::>()) } }