]> git.lizzy.rs Git - rust.git/commitdiff
Avoid to use floating point match
authorest31 <MTest31@outlook.com>
Fri, 14 Apr 2017 00:58:54 +0000 (02:58 +0200)
committerest31 <MTest31@outlook.com>
Fri, 14 Apr 2017 01:39:03 +0000 (03:39 +0200)
Its going to be forbidden, see issue 41255.

src/librand/distributions/gamma.rs

index e024b62adfb15c4756b395215e7abead5016e77c..9a42b82beff67ef674e45aab0779d3cd40e8ac3e 100644 (file)
@@ -103,12 +103,14 @@ pub fn new(shape: f64, scale: f64) -> Gamma {
         assert!(shape > 0.0, "Gamma::new called with shape <= 0");
         assert!(scale > 0.0, "Gamma::new called with scale <= 0");
 
-        let repr = match shape {
-            1.0 => One(Exp::new(1.0 / scale)),
-            0.0...1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
-            _ => Large(GammaLargeShape::new_raw(shape, scale)),
+        let repr = if shape == 1.0 {
+            One(Exp::new(1.0 / scale))
+        } else if 0.0 <= shape && shape < 1.0 {
+            Small(GammaSmallShape::new_raw(shape, scale))
+        } else {
+            Large(GammaLargeShape::new_raw(shape, scale))
         };
-        Gamma { repr: repr }
+        Gamma { repr }
     }
 }