]> git.lizzy.rs Git - rust.git/commitdiff
Make Float::classify matching more clear for f64 and f32
authorBrendan Zabarauskas <bjzaba@yahoo.com.au>
Sun, 12 May 2013 21:57:27 +0000 (07:57 +1000)
committerBrendan Zabarauskas <bjzaba@yahoo.com.au>
Sun, 12 May 2013 21:57:27 +0000 (07:57 +1000)
src/libcore/num/f32.rs
src/libcore/num/f64.rs

index 93e881c50e82f4dafea5bdf06b245492b3795919..a872a6388ba468a0357bebe60653d49266c68b21 100644 (file)
@@ -578,10 +578,7 @@ fn is_finite(&self) -> bool {
     /// 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 @@ fn classify(&self) -> FPCategory {
         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,
         }
     }
 
index 096206d7183010ed29094143daf9d7e09debf95d..8a17ae91934bb62a0198c59616fbae5b293f3460 100644 (file)
@@ -621,10 +621,7 @@ fn is_finite(&self) -> bool {
     /// 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 @@ fn classify(&self) -> FPCategory {
         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,
         }
     }