From c88451c0f0856fe17a498ac8981eb7fca150b90b Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 13 Oct 2023 19:10:59 -0700 Subject: [PATCH] allow partial underflow --- src/integer.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/integer.rs b/src/integer.rs index 60d12a5..2d44c6b 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -439,11 +439,19 @@ pub enum Planar64TryFromFloatError{ } #[inline] fn planar64_from_mes((m,e,s):(u64,i16,i8))->Result{ - if e< -32{ - Err(Planar64TryFromFloatError::HighlyNegativeExponent(e)) - }else if e<32-52{ - Ok(Planar64((m as i64)*(s as i64)<>-e32)==0{//shifting m will underflow to 0 + Ok(Planar64::ZERO) + // println!("m{} e{} s{}",m,e,s); + // println!("f={}",(m as f64)*(2.0f64.powf(e as f64))*(s as f64)); + // Err(Planar64TryFromFloatError::HighlyNegativeExponent(e)) + }else if (64-m.leading_zeros() as i16)+e32<64{//shifting m will not overflow + if e32<0{ + Ok(Planar64((m as i64)*(s as i64)>>-e32)) + }else{ + Ok(Planar64((m as i64)*(s as i64)<