div_euclid

This commit is contained in:
Quaternions 2024-10-12 10:01:06 -07:00
parent a274b6d232
commit c5fb915a6d

View File

@ -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<const F:usize> $struct<$width,F>{
paste::item!{
#[inline]
pub fn [<fixed_ $method>](self, other: Self) -> Self {
pub fn [<fixed_ $method>](self,other:Self)->Self{
//this only needs to be $width+F as u32/64+1 but MUH CONST GENERICS!!!!!
let lhs=self.bits.as_::<BInt::<{$width*2}>>().shl(F as u32);
let rhs=other.bits.as_::<BInt::<{$width*2}>>();
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<const N:usize,const F:usize,U> core::ops::$trait<U> for $struct<N,F>
where
BInt::<N>:From<U>+core::ops::$trait,
{
type Output = $output;
#[inline]
fn $method(self, other: U) -> Self::Output {
Self::from_bits(self.bits.$method(BInt::<N>::from(other)))
fn $method(self,other:U)->Self::Output{
Self::from_bits(self.bits.$inner_method(BInt::<N>::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<const N:usize,const F:usize,U> core::ops::$trait<U> for $struct<N,F>
where
BInt::<N>:From<U>+core::ops::$trait,
{
#[inline]
fn $method(&mut self, other: U) {
self.bits.$method(BInt::<N>::from(other));
fn $method(&mut self,other:U){
self.bits=self.bits.$not_assign_method(BInt::<N>::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<const LHS_N:usize,const LHS_F:usize,const RHS_N:usize,const RHS_F:usize> core::ops::Div<Fixed<RHS_N,RHS_F>> for Fixed<LHS_N,LHS_F>{
type Output=ratio_ops::ratio::Ratio<Fixed<LHS_N,LHS_F>,Fixed<RHS_N,RHS_F>>;