Skip to content

Commit 6f5f6d7

Browse files
committed
Using is_finite, formatted the code
1 parent a81c4ae commit 6f5f6d7

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

src/biguint.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ impl Roots for BigUint {
16881688

16891689
#[cfg(feature = "std")]
16901690
let guess = match self.to_f64() {
1691-
Some(f) if f != f64::INFINITY => {
1691+
Some(f) if f.is_finite() => {
16921692
// We fit in `f64` (lossy), so get a better initial guess from that.
16931693
BigUint::from_f64((f.ln() / f64::from(n)).exp()).unwrap()
16941694
}
@@ -1734,7 +1734,7 @@ impl Roots for BigUint {
17341734

17351735
#[cfg(feature = "std")]
17361736
let guess = match self.to_f64() {
1737-
Some(f) if f != f64::INFINITY => {
1737+
Some(f) if f.is_finite() => {
17381738
// We fit in `f64` (lossy), so get a better initial guess from that.
17391739
BigUint::from_f64(f.sqrt()).unwrap()
17401740
}
@@ -1773,7 +1773,7 @@ impl Roots for BigUint {
17731773

17741774
#[cfg(feature = "std")]
17751775
let guess = match self.to_f64() {
1776-
Some(f) if f != f64::INFINITY => {
1776+
Some(f) if f.is_finite() => {
17771777
// We fit in `f64` (lossy), so get a better initial guess from that.
17781778
BigUint::from_f64(f.cbrt()).unwrap()
17791779
}

tests/bigint.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,19 @@ fn test_convert_f32() {
452452
assert_eq!((-&big_num).to_f32(), Some(f32::MIN));
453453
assert_eq!(((-&big_num) - 1u8).to_f32(), Some(f32::NEG_INFINITY));
454454

455-
assert_eq!(((BigInt::one() << 128u8) - 1u8).to_f32(), Some(f32::INFINITY));
455+
assert_eq!(
456+
((BigInt::one() << 128u8) - 1u8).to_f32(),
457+
Some(f32::INFINITY)
458+
);
456459
assert_eq!((BigInt::one() << 128u8).to_f32(), Some(f32::INFINITY));
457-
assert_eq!((-((BigInt::one() << 128u8) - 1u8)).to_f32(), Some(f32::NEG_INFINITY));
458-
assert_eq!((-(BigInt::one() << 128u8)).to_f32(), Some(f32::NEG_INFINITY));
460+
assert_eq!(
461+
(-((BigInt::one() << 128u8) - 1u8)).to_f32(),
462+
Some(f32::NEG_INFINITY)
463+
);
464+
assert_eq!(
465+
(-(BigInt::one() << 128u8)).to_f32(),
466+
Some(f32::NEG_INFINITY)
467+
);
459468
}
460469

461470
#[test]
@@ -533,10 +542,19 @@ fn test_convert_f64() {
533542
assert_eq!((-&big_num).to_f64(), Some(f64::MIN));
534543
assert_eq!(((-&big_num) - 1u8).to_f64(), Some(f64::NEG_INFINITY));
535544

536-
assert_eq!(((BigInt::one() << 1024u16) - 1u8).to_f64(), Some(f64::INFINITY));
545+
assert_eq!(
546+
((BigInt::one() << 1024u16) - 1u8).to_f64(),
547+
Some(f64::INFINITY)
548+
);
537549
assert_eq!((BigInt::one() << 1024u16).to_f64(), Some(f64::INFINITY));
538-
assert_eq!((-((BigInt::one() << 1024u16) - 1u8)).to_f64(), Some(f64::NEG_INFINITY));
539-
assert_eq!((-(BigInt::one() << 1024u16)).to_f64(), Some(f64::NEG_INFINITY));
550+
assert_eq!(
551+
(-((BigInt::one() << 1024u16) - 1u8)).to_f64(),
552+
Some(f64::NEG_INFINITY)
553+
);
554+
assert_eq!(
555+
(-(BigInt::one() << 1024u16)).to_f64(),
556+
Some(f64::NEG_INFINITY)
557+
);
540558
}
541559

542560
#[test]

tests/biguint.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,10 @@ fn test_convert_f32() {
675675
assert_eq!(big_num.to_f32(), Some(f32::MAX));
676676
assert_eq!((big_num + 1u8).to_f32(), Some(f32::INFINITY));
677677

678-
assert_eq!(((BigUint::one() << 128u8) - 1u8).to_f32(), Some(f32::INFINITY));
678+
assert_eq!(
679+
((BigUint::one() << 128u8) - 1u8).to_f32(),
680+
Some(f32::INFINITY)
681+
);
679682
assert_eq!((BigUint::one() << 128u8).to_f32(), Some(f32::INFINITY));
680683
}
681684

@@ -748,7 +751,10 @@ fn test_convert_f64() {
748751
assert_eq!(big_num.to_f64(), Some(f64::MAX));
749752
assert_eq!((big_num + 1u8).to_f64(), Some(f64::INFINITY));
750753

751-
assert_eq!(((BigUint::one() << 1024u16) - 1u8).to_f64(), Some(f64::INFINITY));
754+
assert_eq!(
755+
((BigUint::one() << 1024u16) - 1u8).to_f64(),
756+
Some(f64::INFINITY)
757+
);
752758
assert_eq!((BigUint::one() << 1024u16).to_f64(), Some(f64::INFINITY));
753759
}
754760

0 commit comments

Comments
 (0)