Skip to content

Commit 4f8084a

Browse files
committed
Make Float::classify matching more clear for f64 and f32
1 parent 36771ef commit 4f8084a

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

src/libcore/num/f32.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,7 @@ impl Float for f32 {
578578
/// Returns `true` if the number is neither zero, infinite, subnormal or NaN
579579
#[inline(always)]
580580
fn is_normal(&self) -> bool {
581-
match self.classify() {
582-
FPNormal => true,
583-
_ => false,
584-
}
581+
self.classify() == FPNormal
585582
}
586583

587584
/// Returns the floating point category of the number. If only one property is going to
@@ -591,14 +588,14 @@ impl Float for f32 {
591588
static MAN_MASK: u32 = 0x007fffff;
592589

593590
match (
591+
unsafe { ::cast::transmute::<f32,u32>(*self) } & MAN_MASK,
594592
unsafe { ::cast::transmute::<f32,u32>(*self) } & EXP_MASK,
595-
unsafe { ::cast::transmute::<f32,u32>(*self) } & MAN_MASK
596593
) {
597-
(EXP_MASK, 0) => FPInfinite,
598-
(EXP_MASK, _) => FPNaN,
599-
(exp, _) if exp != 0 => FPNormal,
600-
_ if self.is_zero() => FPZero,
601-
_ => FPSubnormal,
594+
(0, 0) => FPZero,
595+
(_, 0) => FPSubnormal,
596+
(0, EXP_MASK) => FPInfinite,
597+
(_, EXP_MASK) => FPNaN,
598+
_ => FPNormal,
602599
}
603600
}
604601

src/libcore/num/f64.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,7 @@ impl Float for f64 {
621621
/// Returns `true` if the number is neither zero, infinite, subnormal or NaN
622622
#[inline(always)]
623623
fn is_normal(&self) -> bool {
624-
match self.classify() {
625-
FPNormal => true,
626-
_ => false,
627-
}
624+
self.classify() == FPNormal
628625
}
629626

630627
/// Returns the floating point category of the number. If only one property is going to
@@ -634,14 +631,14 @@ impl Float for f64 {
634631
static MAN_MASK: u64 = 0x000fffffffffffff;
635632

636633
match (
634+
unsafe { ::cast::transmute::<f64,u64>(*self) } & MAN_MASK,
637635
unsafe { ::cast::transmute::<f64,u64>(*self) } & EXP_MASK,
638-
unsafe { ::cast::transmute::<f64,u64>(*self) } & MAN_MASK
639636
) {
640-
(EXP_MASK, 0) => FPInfinite,
641-
(EXP_MASK, _) => FPNaN,
642-
(exp, _) if exp != 0 => FPNormal,
643-
_ if self.is_zero() => FPZero,
644-
_ => FPSubnormal,
637+
(0, 0) => FPZero,
638+
(_, 0) => FPSubnormal,
639+
(0, EXP_MASK) => FPInfinite,
640+
(_, EXP_MASK) => FPNaN,
641+
_ => FPNormal,
645642
}
646643
}
647644

0 commit comments

Comments
 (0)