diff --git a/fixed_wide/src/fixed.rs b/fixed_wide/src/fixed.rs index ab18621..2c13bc6 100644 --- a/fixed_wide/src/fixed.rs +++ b/fixed_wide/src/fixed.rs @@ -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 $struct<$chunks,Frac>{ + pub fn sqrt(self)->$struct<{$chunks/2+1},typenum::PartialDiv>{ + $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);