about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrendan Zabarauskas <bjzaba@yahoo.com.au>2013-05-13 07:57:27 +1000
committerBrendan Zabarauskas <bjzaba@yahoo.com.au>2013-05-13 07:57:27 +1000
commit4f8084a363b352e4a1d75f9ab53f6defcb65d366 (patch)
tree939a02b8801d687348a8acfddd997878ddfa849e
parent36771ef60997b5882ad391839b5f7854d077cc42 (diff)
downloadrust-4f8084a363b352e4a1d75f9ab53f6defcb65d366.tar.gz
rust-4f8084a363b352e4a1d75f9ab53f6defcb65d366.zip
Make Float::classify matching more clear for f64 and f32
-rw-r--r--src/libcore/num/f32.rs17
-rw-r--r--src/libcore/num/f64.rs17
2 files changed, 14 insertions, 20 deletions
diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs
index 93e881c50e8..a872a6388ba 100644
--- a/src/libcore/num/f32.rs
+++ b/src/libcore/num/f32.rs
@@ -578,10 +578,7 @@ impl Float for f32 {
     /// Returns `true` if the number is neither zero, infinite, subnormal or NaN
     #[inline(always)]
     fn is_normal(&self) -> bool {
-        match self.classify() {
-            FPNormal => true,
-            _ => false,
-        }
+        self.classify() == FPNormal
     }
 
     /// Returns the floating point category of the number. If only one property is going to
@@ -591,14 +588,14 @@ impl Float for f32 {
         static MAN_MASK: u32 = 0x007fffff;
 
         match (
+            unsafe { ::cast::transmute::<f32,u32>(*self) } & MAN_MASK,
             unsafe { ::cast::transmute::<f32,u32>(*self) } & EXP_MASK,
-            unsafe { ::cast::transmute::<f32,u32>(*self) } & MAN_MASK
         ) {
-            (EXP_MASK, 0)        => FPInfinite,
-            (EXP_MASK, _)        => FPNaN,
-            (exp, _) if exp != 0 => FPNormal,
-            _ if self.is_zero()  => FPZero,
-            _                    => FPSubnormal,
+            (0, 0)        => FPZero,
+            (_, 0)        => FPSubnormal,
+            (0, EXP_MASK) => FPInfinite,
+            (_, EXP_MASK) => FPNaN,
+            _             => FPNormal,
         }
     }
 
diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs
index 096206d7183..8a17ae91934 100644
--- a/src/libcore/num/f64.rs
+++ b/src/libcore/num/f64.rs
@@ -621,10 +621,7 @@ impl Float for f64 {
     /// Returns `true` if the number is neither zero, infinite, subnormal or NaN
     #[inline(always)]
     fn is_normal(&self) -> bool {
-        match self.classify() {
-            FPNormal => true,
-            _ => false,
-        }
+        self.classify() == FPNormal
     }
 
     /// Returns the floating point category of the number. If only one property is going to
@@ -634,14 +631,14 @@ impl Float for f64 {
         static MAN_MASK: u64 = 0x000fffffffffffff;
 
         match (
+            unsafe { ::cast::transmute::<f64,u64>(*self) } & MAN_MASK,
             unsafe { ::cast::transmute::<f64,u64>(*self) } & EXP_MASK,
-            unsafe { ::cast::transmute::<f64,u64>(*self) } & MAN_MASK
         ) {
-            (EXP_MASK, 0)        => FPInfinite,
-            (EXP_MASK, _)        => FPNaN,
-            (exp, _) if exp != 0 => FPNormal,
-            _ if self.is_zero()  => FPZero,
-            _                    => FPSubnormal,
+            (0, 0)        => FPZero,
+            (_, 0)        => FPSubnormal,
+            (0, EXP_MASK) => FPInfinite,
+            (_, EXP_MASK) => FPNaN,
+            _             => FPNormal,
         }
     }