From 491de52f17586c53abbb9014660bea4d980be3ea Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 29 Aug 2024 10:42:50 -0700 Subject: [PATCH] improve failure mode --- fixed_wide/src/fixed.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/fixed_wide/src/fixed.rs b/fixed_wide/src/fixed.rs index 9ed0f1a..7abb1fc 100644 --- a/fixed_wide/src/fixed.rs +++ b/fixed_wide/src/fixed.rs @@ -155,24 +155,23 @@ impl_shift_operator!( Fixed, Shr, shr, Self ); impl Fixed{ pub fn sqrt_unchecked(self)->Self{ - let mut pow2=if self==Self::ZERO{ - return Self::ZERO; - }else if self>=1; } pow2 - }else if self==Self::ONE{ - return Self::ONE; - }else{ - //find pow2 more powerful than self - let mut pow2=Self::ONE; - while pow2<=self{ - pow2<<=1; - } - pow2 + }else{//either 0==self or self is negative + return Self::ZERO; }; let mut result=pow2; while pow2!=Self::ZERO{