wide operators

This commit is contained in:
Quaternions 2024-09-09 13:58:47 -07:00
parent 503f5b6d22
commit b98eba27e5

View File

@ -178,6 +178,7 @@ macro_rules! impl_multiply_operator_not_const_generic {
}
}
}
#[cfg(not(feature="wide-mul"))]
impl_multiplicative_operator_not_const_generic!(($struct, $trait, $method, $output ), $width);
}
}
@ -194,6 +195,7 @@ macro_rules! impl_divide_operator_not_const_generic {
}
}
}
#[cfg(not(feature="wide-mul"))]
impl_multiplicative_operator_not_const_generic!(($struct, $trait, $method, $output ), $width);
};
}
@ -279,6 +281,19 @@ impl_shift_operator!( Fixed, Shl, shl, Self );
impl_shift_assign_operator!( Fixed, ShrAssign, shr_assign );
impl_shift_operator!( Fixed, Shr, shr, Self );
macro_rules! impl_wide_operators{
($lhs:expr,$rhs:expr)=>{
impl core::ops::Mul<Fixed<$rhs,{$rhs*32}>> for Fixed<$lhs,{$lhs*32}>{
type Output=Fixed<{$lhs+$rhs},{($lhs+$rhs)*32}>;
fn mul(self, other: Fixed<$rhs,{$rhs*32}>)->Self::Output{
paste::item!{
self.[<wide_mul_ $lhs _ $rhs>](other)
}
}
}
}
}
// WIDE MUL: multiply into a wider type
// let a = I32F32::ONE;
// let b:I64F64 = a.wide_mul(a);
@ -306,6 +321,8 @@ macro_rules! impl_wide_not_const_generic{
}
}
}
#[cfg(feature="wide-mul")]
impl_wide_operators!($lhs,$rhs);
};
}