From 75bd98ce193c59a454456935f537e6d6dc1009e0 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 29 Aug 2024 16:17:48 -0700 Subject: [PATCH] sqrt --- src/integer.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/integer.rs b/src/integer.rs index 377a097..c034fd9 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -453,7 +453,23 @@ impl Planar64{ } #[inline] pub fn sqrt(&self)->Self{ - Planar64(unsafe{(((self.0 as i128)<<32) as f64).sqrt().to_int_unchecked()}) + const BITS:i32=64; + const FRAC:i32=32; + let mut pow2=Self::raw(1i64<<(((BITS-FRAC-(self.0.leading_zeros() as i32)+1)>>1)+FRAC).saturating_sub(1)); + let mut result=pow2; + let wide_self=(self.0 as i128)<(), + core::cmp::Ordering::Equal=>break new_result, + core::cmp::Ordering::Greater=>result=new_result, + } + pow2=Self::raw(pow2.0>>1); + } } #[inline] pub const fn signum_i64(&self)->i64{