From b45d93a7dc65c50cefc9299e6c2daf9cfe07e838 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 29 Aug 2024 13:16:09 -0700 Subject: [PATCH] more sqrt tests --- fixed_wide/src/tests.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fixed_wide/src/tests.rs b/fixed_wide/src/tests.rs index 3b40d7f..05c911a 100644 --- a/fixed_wide/src/tests.rs +++ b/fixed_wide/src/tests.rs @@ -25,3 +25,22 @@ fn test_sqrt_low(){ let b=a*a; assert_eq!(b.sqrt(),a); } +fn find_equiv_sqrt_via_f64(n:I32F32)->I32F32{ + //GIMME THEM BITS BOY + let &[bits]=n.to_bits().to_bits().digits(); + let ibits=bits as i64; + let f=(ibits as f64)/((1u64<<32) as f64); + let f_ans=f.sqrt(); + let mut i=(f_ans*((1u64<<32) as f64)) as i64; + let s=(i as i128)*(i as i128); + if s<((ibits as i128)<<32){ + i+=1; + } + I32F32::from_bits(bnum::BInt::<1>::from(i)) +} +#[test] +fn test_sqrt_exact(){ + let a=I32F32::ONE*2; + let b=find_equiv_sqrt_via_f64(a); + assert_eq!(a.sqrt(),b); +}