From 502ab7f33f09e62be9ee4543cbb7ff710f14364e Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 2 Sep 2024 17:09:37 -0700 Subject: [PATCH] named function --- fixed_wide/src/fixed.rs | 5 +++++ fixed_wide/src/zeroes.rs | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fixed_wide/src/fixed.rs b/fixed_wide/src/fixed.rs index 81494a3..d0aad2d 100644 --- a/fixed_wide/src/fixed.rs +++ b/fixed_wide/src/fixed.rs @@ -320,6 +320,11 @@ impl Fixed{ macro_rules! impl_const{ ($n:expr)=>{ + impl Fixed<{$n*2},{$n*2*32}>{ + pub fn halve_precision(self)->Fixed<$n,{$n*32}>{ + Fixed::from_bits(bnum::cast::As::as_(self.bits.shr($n*32))) + } + } impl Fixed<$n,{$n*32}>{ paste::item!{ pub fn sqrt_unchecked(self)->Self{ diff --git a/fixed_wide/src/zeroes.rs b/fixed_wide/src/zeroes.rs index 16d211d..97da6c9 100644 --- a/fixed_wide/src/zeroes.rs +++ b/fixed_wide/src/zeroes.rs @@ -19,9 +19,7 @@ macro_rules! impl_zeroes{ Ordering::Greater=>{ //start with f64 sqrt //failure case: 2^63 < sqrt(2^127) - let planar_radicand_wide=radicand.sqrt(); - //lazy hack - let planar_radicand=Self::from_bits(bnum::cast::As::as_(planar_radicand_wide.bits.shr($n*32))); + let planar_radicand=radicand.sqrt().halve_precision(); //TODO: one or two newtons //sort roots ascending and avoid taking the difference of large numbers match (a2pos,Self::ZERO