From 7181b1274be8565a2a9b12d15ce34c33ce532ad9 Mon Sep 17 00:00:00 2001 From: Jacob Date: Thu, 11 Jan 2024 17:21:13 +0800 Subject: [PATCH] Cargo fmt & clippy --- float/src/convert.rs | 4 +--- float/src/third_party/num_order.rs | 4 ++-- float/src/third_party/rand.rs | 5 ++++- float/tests/num_order.rs | 20 ++++++++++++++------ 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/float/src/convert.rs b/float/src/convert.rs index bc7ba3f..d68aa46 100644 --- a/float/src/convert.rs +++ b/float/src/convert.rs @@ -53,9 +53,7 @@ macro_rules! impl_from_float_for_fbig { fn try_from(f: $t) -> Result { match f.decode() { - Ok((man, exp)) => { - Ok(Repr::new(man.into(), exp as _)) - } + Ok((man, exp)) => Ok(Repr::new(man.into(), exp as _)), Err(FpCategory::Infinite) => match f.sign() { Sign::Positive => Ok(Self::infinity()), Sign::Negative => Ok(Self::neg_infinity()), diff --git a/float/src/third_party/num_order.rs b/float/src/third_party/num_order.rs index 18c27b4..8d0ae46 100644 --- a/float/src/third_party/num_order.rs +++ b/float/src/third_party/num_order.rs @@ -1,6 +1,6 @@ use _num_modular::{FixedMersenneInt, ModularAbs, ModularInteger}; use core::cmp::Ordering; -use dashu_base::{EstimatedLog2, Sign, Signed, BitTest, FloatEncoding}; +use dashu_base::{BitTest, EstimatedLog2, FloatEncoding, Sign, Signed}; use dashu_int::{IBig, UBig, Word}; use num_order::{NumHash, NumOrd}; @@ -343,7 +343,7 @@ macro_rules! impl_num_ord_fbig_with_float { Some(lhs.cmp(&rhs)) } } - + impl NumOrd> for $t { #[inline] fn num_partial_cmp(&self, other: &Repr) -> Option { diff --git a/float/src/third_party/rand.rs b/float/src/third_party/rand.rs index 55f468e..9adbff7 100644 --- a/float/src/third_party/rand.rs +++ b/float/src/third_party/rand.rs @@ -142,7 +142,10 @@ impl Distribution> for UniformFBig { let unit: FBig = self.sampler.sample(rng); let context = unit.context(); let scaled = context.mul(unit.repr(), &self.scale).value(); - context.add(scaled.repr(), &self.offset).value().with_rounding() + context + .add(scaled.repr(), &self.offset) + .value() + .with_rounding() } } diff --git a/float/tests/num_order.rs b/float/tests/num_order.rs index b4242c5..fe48f00 100644 --- a/float/tests/num_order.rs +++ b/float/tests/num_order.rs @@ -1,6 +1,6 @@ +use core::cmp::Ordering; use dashu_float::{DBig, FBig}; use num_order::{NumHash, NumOrd}; -use core::cmp::Ordering; mod helper_macros; @@ -135,6 +135,8 @@ fn test_hash() { } #[test] +#[rustfmt::skip::macros(fbig)] +#[allow(clippy::approx_constant)] fn test_primitive_floats() { // trivial cases assert_eq!(fbig!(0).num_cmp(&0f32), Ordering::Equal); @@ -152,7 +154,7 @@ fn test_primitive_floats() { assert_eq!(FBin::NEG_INFINITY.num_cmp(&0f32), Ordering::Less); assert_eq!(FBin::NEG_INFINITY.num_cmp(&f32::NEG_INFINITY), Ordering::Equal); assert_eq!(fbig!(0).num_partial_cmp(&f32::NAN), None); - + assert_eq!(dbig!(0).num_cmp(&0f64), Ordering::Equal); assert_eq!(dbig!(0).num_cmp(&1f64), Ordering::Less); assert_eq!(dbig!(0).num_cmp(&-1f64), Ordering::Greater); @@ -178,7 +180,7 @@ fn test_primitive_floats() { assert_eq!(fbig!(0x1).num_cmp(&1e10f32), Ordering::Less); assert_eq!(fbig!(-0x1p100).num_cmp(&1e-10f32), Ordering::Less); assert_eq!(fbig!(0x1p-100).num_cmp(&-1e10f32), Ordering::Greater); - + assert_eq!(dbig!(1e100).num_cmp(&1e10f64), Ordering::Greater); assert_eq!(dbig!(1e10).num_cmp(&1f64), Ordering::Greater); assert_eq!(dbig!(1).num_cmp(&1e-10f64), Ordering::Greater); @@ -193,9 +195,15 @@ fn test_primitive_floats() { assert_eq!(fbig!(0x1921fb4001p-35).num_cmp(&3.1415926f32), Ordering::Greater); assert_eq!(fbig!(0x1921fb3fffp-35).num_cmp(&3.1415926f32), Ordering::Less); assert_eq!(fbig!(0x1921fb54442d18p-51).num_cmp(&3.141592653589793f64), Ordering::Equal); - assert_eq!(fbig!(0x1921fb54442d180000000001p-91).num_cmp(&3.141592653589793f64), Ordering::Greater); - assert_eq!(fbig!(0x1921fb54442d17ffffffffffp-91).num_cmp(&3.141592653589793f64), Ordering::Less); - + assert_eq!( + fbig!(0x1921fb54442d180000000001p-91).num_cmp(&3.141592653589793f64), + Ordering::Greater + ); + assert_eq!( + fbig!(0x1921fb54442d17ffffffffffp-91).num_cmp(&3.141592653589793f64), + Ordering::Less + ); + // exact value 3.1415926f32 = 3.141592502593994140625​ assert_eq!(dbig!(3.1415926).num_cmp(&3.1415926f32), Ordering::Greater); assert_eq!(dbig!(3.1415925).num_cmp(&3.1415926f32), Ordering::Less);