how to do bnum sqrt

This commit is contained in:
Quaternions 2024-08-27 16:50:43 -07:00
parent c43fab2f18
commit e878644a48

View File

@ -125,3 +125,19 @@ impl_shift_assign_operator!( Fixed, ShlAssign, shl_assign );
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_sqrt {
( $struct: ident, $chunks: expr) => {
impl<Frac:Unsigned> $struct<$chunks,Frac>{
pub fn sqrt(self)->$struct<{$chunks/2+1},typenum::PartialDiv<Frac,typenum::U2>>{
$struct{
bits:self.bits.sqrt(),
frac:PhantomData,
}
}
}
};
}
impl_sqrt!(Fixed,1);impl_sqrt!(Fixed,2);impl_sqrt!(Fixed,3);impl_sqrt!(Fixed,4);impl_sqrt!(Fixed,5);impl_sqrt!(Fixed,6);impl_sqrt!(Fixed,7);impl_sqrt!(Fixed,8);
impl_sqrt!(Fixed,9);impl_sqrt!(Fixed,10);impl_sqrt!(Fixed,11);impl_sqrt!(Fixed,12);impl_sqrt!(Fixed,13);impl_sqrt!(Fixed,14);impl_sqrt!(Fixed,15);impl_sqrt!(Fixed,16);