Skip to content

Commit

Permalink
Cargo fmt & clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
cmpute committed Jan 11, 2024
1 parent 6b796e2 commit 7181b12
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
4 changes: 1 addition & 3 deletions float/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ macro_rules! impl_from_float_for_fbig {

fn try_from(f: $t) -> Result<Self, Self::Error> {
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()),
Expand Down
4 changes: 2 additions & 2 deletions float/src/third_party/num_order.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -343,7 +343,7 @@ macro_rules! impl_num_ord_fbig_with_float {
Some(lhs.cmp(&rhs))
}
}

impl<const B: Word> NumOrd<Repr<B>> for $t {
#[inline]
fn num_partial_cmp(&self, other: &Repr<B>) -> Option<Ordering> {
Expand Down
5 changes: 4 additions & 1 deletion float/src/third_party/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ impl<R: Round, const B: Word> Distribution<FBig<R, B>> for UniformFBig<R, B> {
let unit: FBig<mode::Down, B> = 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()
}
}

Expand Down
20 changes: 14 additions & 6 deletions float/tests/num_order.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 7181b12

Please sign in to comment.