Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
d4cfb9cd47 | |||
b11a060042 | |||
e38126302e | |||
75bd98ce19 |
@ -453,7 +453,20 @@ 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 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]
|
||||
pub const fn signum_i64(&self)->i64{
|
||||
|
Loading…
Reference in New Issue
Block a user