This commit is contained in:
Quaternions 2024-08-29 10:42:11 -07:00
parent 9f6dffafda
commit 69da2c52a4

View File

@ -62,47 +62,47 @@ impl<const CHUNKS:usize,Frac> std::ops::Neg for Fixed<CHUNKS,Frac>{
macro_rules! impl_operator { macro_rules! impl_operator {
( $struct: ident, $trait: ident, $method: ident, $output: ty ) => { ( $struct: ident, $trait: ident, $method: ident, $output: ty ) => {
impl<const CHUNKS:usize,Frac> core::ops::$trait for $struct<CHUNKS,Frac>{ impl<const CHUNKS:usize,Frac> core::ops::$trait for $struct<CHUNKS,Frac>{
type Output = $output; type Output = $output;
fn $method(self, other: Self) -> Self::Output { fn $method(self, other: Self) -> Self::Output {
Self { Self {
bits:self.bits.$method(other.bits), bits:self.bits.$method(other.bits),
frac:PhantomData, frac:PhantomData,
} }
} }
} }
impl<const CHUNKS:usize,Frac:Unsigned,U> core::ops::$trait<U> for $struct<CHUNKS,Frac> impl<const CHUNKS:usize,Frac:Unsigned,U> core::ops::$trait<U> for $struct<CHUNKS,Frac>
where where
BInt::<CHUNKS>:From<U>, BInt::<CHUNKS>:From<U>,
{ {
type Output = $output; type Output = $output;
fn $method(self, other: U) -> Self::Output { fn $method(self, other: U) -> Self::Output {
Self { Self {
bits:self.bits.$method(BInt::<CHUNKS>::from(other)<<Frac::U32), bits:self.bits.$method(BInt::<CHUNKS>::from(other)<<Frac::U32),
frac:PhantomData, frac:PhantomData,
} }
} }
} }
}; };
} }
macro_rules! impl_assign_operator { macro_rules! impl_assign_operator {
( $struct: ident, $trait: ident, $method: ident ) => { ( $struct: ident, $trait: ident, $method: ident ) => {
impl<const CHUNKS:usize,Frac> core::ops::$trait for $struct<CHUNKS,Frac>{ impl<const CHUNKS:usize,Frac> core::ops::$trait for $struct<CHUNKS,Frac>{
fn $method(&mut self, other: Self) { fn $method(&mut self, other: Self) {
self.bits.$method(other.bits); self.bits.$method(other.bits);
} }
} }
impl<const CHUNKS:usize,Frac:Unsigned,U> core::ops::$trait<U> for $struct<CHUNKS,Frac> impl<const CHUNKS:usize,Frac:Unsigned,U> core::ops::$trait<U> for $struct<CHUNKS,Frac>
where where
BInt::<CHUNKS>:From<U>, BInt::<CHUNKS>:From<U>,
{ {
fn $method(&mut self, other: U) { fn $method(&mut self, other: U) {
self.bits.$method(BInt::<CHUNKS>::from(other)<<Frac::U32); self.bits.$method(BInt::<CHUNKS>::from(other)<<Frac::U32);
} }
} }
}; };
} }
// Impl arithmetic pperators // Impl arithmetic pperators
@ -127,26 +127,26 @@ impl_operator!( Fixed, BitXor, bitxor, Self );
macro_rules! impl_shift_operator { macro_rules! impl_shift_operator {
( $struct: ident, $trait: ident, $method: ident, $output: ty ) => { ( $struct: ident, $trait: ident, $method: ident, $output: ty ) => {
impl<const CHUNKS:usize,Frac> core::ops::$trait<u32> for $struct<CHUNKS,Frac>{ impl<const CHUNKS:usize,Frac> core::ops::$trait<u32> for $struct<CHUNKS,Frac>{
type Output = $output; type Output = $output;
fn $method(self, other: u32) -> Self::Output { fn $method(self, other: u32) -> Self::Output {
Self { Self {
bits:self.bits.$method(other), bits:self.bits.$method(other),
frac:PhantomData, frac:PhantomData,
} }
} }
} }
}; };
} }
macro_rules! impl_shift_assign_operator { macro_rules! impl_shift_assign_operator {
( $struct: ident, $trait: ident, $method: ident ) => { ( $struct: ident, $trait: ident, $method: ident ) => {
impl<const CHUNKS:usize,Frac> core::ops::$trait<u32> for $struct<CHUNKS,Frac>{ impl<const CHUNKS:usize,Frac> core::ops::$trait<u32> for $struct<CHUNKS,Frac>{
fn $method(&mut self, other: u32) { fn $method(&mut self, other: u32) {
self.bits.$method(other); self.bits.$method(other);
} }
} }
}; };
} }
impl_shift_assign_operator!( Fixed, ShlAssign, shl_assign ); impl_shift_assign_operator!( Fixed, ShlAssign, shl_assign );
impl_shift_operator!( Fixed, Shl, shl, Self ); impl_shift_operator!( Fixed, Shl, shl, Self );