This commit is contained in:
Quaternions 2024-08-29 16:17:48 -07:00
parent 79011171cb
commit 75bd98ce19

View File

@ -453,7 +453,23 @@ 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 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)<<FRAC;
loop{
if pow2==Self::ZERO{
break result;
}
let new_result=result+pow2;
match wide_self.cmp(&((new_result.0 as i128)*(new_result.0 as i128))){
core::cmp::Ordering::Less=>(),
core::cmp::Ordering::Equal=>break new_result,
core::cmp::Ordering::Greater=>result=new_result,
}
pow2=Self::raw(pow2.0>>1);
}
} }
#[inline] #[inline]
pub const fn signum_i64(&self)->i64{ pub const fn signum_i64(&self)->i64{