Compare commits

...

4 Commits
master ... sqrt

Author SHA1 Message Date
d4cfb9cd47 fix zero 2024-08-29 17:05:37 -07:00
b11a060042 bits don't conflict 2024-08-29 16:37:04 -07:00
e38126302e improve sqrt 2024-08-29 16:24:13 -07:00
75bd98ce19 sqrt 2024-08-29 16:17:48 -07:00

View File

@ -453,7 +453,20 @@ impl Planar64{
} }
#[inline] #[inline]
pub fn sqrt(&self)->Self{ 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 pow=(((BITS-FRAC-(self.0.leading_zeros() as i32)+1)>>1)+FRAC)-1;
let mut result=Self::ZERO;
let wide_self=(self.0 as i128)<<FRAC;
for i in (0..=pow).rev(){
let new_result=Self::raw(result.0|1<<i);
match wide_self.cmp(&((new_result.0 as i128)*(new_result.0 as i128))){
core::cmp::Ordering::Less=>(),
core::cmp::Ordering::Equal=>return new_result,
core::cmp::Ordering::Greater=>result=new_result,
}
}
result
} }
#[inline] #[inline]
pub const fn signum_i64(&self)->i64{ pub const fn signum_i64(&self)->i64{