about summary refs log tree commit diff
path: root/src/libstd/num
diff options
context:
space:
mode:
authorMichael Darakananda <pongad@gmail.com>2014-02-06 02:34:33 -0500
committerMichael Darakananda <pongad@gmail.com>2014-02-13 20:12:59 -0500
commitbf1464c413bb2564c7be0eaceef9515bc0f94f1f (patch)
treeb956233c5e7c587d1faecbadb307117cda24952a /src/libstd/num
parent94d453e459107ed1c5d76f693686b29d31cdc58c (diff)
downloadrust-bf1464c413bb2564c7be0eaceef9515bc0f94f1f.tar.gz
rust-bf1464c413bb2564c7be0eaceef9515bc0f94f1f.zip
Removed num::Orderable
Diffstat (limited to 'src/libstd/num')
-rw-r--r--src/libstd/num/f32.rs60
-rw-r--r--src/libstd/num/f64.rs68
-rw-r--r--src/libstd/num/int_macros.rs29
-rw-r--r--src/libstd/num/mod.rs23
-rw-r--r--src/libstd/num/uint_macros.rs33
5 files changed, 3 insertions, 210 deletions
diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs
index a4b6aca86f7..9951405fa0c 100644
--- a/src/libstd/num/f32.rs
+++ b/src/libstd/num/f32.rs
@@ -189,42 +189,6 @@ impl Ord for f32 {
     fn gt(&self, other: &f32) -> bool { (*self) > (*other) }
 }
 
-impl Orderable for f32 {
-    /// Returns `NAN` if either of the numbers are `NAN`.
-    #[inline]
-    fn min(&self, other: &f32) -> f32 {
-        match () {
-            _ if self.is_nan()  => *self,
-            _ if other.is_nan() => *other,
-            _ if *self < *other => *self,
-            _                   => *other,
-        }
-    }
-
-    /// Returns `NAN` if either of the numbers are `NAN`.
-    #[inline]
-    fn max(&self, other: &f32) -> f32 {
-        match () {
-            _ if self.is_nan()  => *self,
-            _ if other.is_nan() => *other,
-            _ if *self > *other => *self,
-            _                   => *other,
-        }
-    }
-
-    /// Returns the number constrained within the range `mn <= self <= mx`.
-    /// If any of the numbers are `NAN` then `NAN` is returned.
-    #[inline]
-    fn clamp(&self, mn: &f32, mx: &f32) -> f32 {
-        match () {
-            _ if self.is_nan()   => *self,
-            _ if !(*self <= *mx) => *mx,
-            _ if !(*self >= *mn) => *mn,
-            _                    => *self,
-        }
-    }
-}
-
 impl Default for f32 {
     #[inline]
     fn default() -> f32 { 0.0 }
@@ -914,30 +878,6 @@ mod tests {
     }
 
     #[test]
-    fn test_min() {
-        assert_eq!(1f32.min(&2f32), 1f32);
-        assert_eq!(2f32.min(&1f32), 1f32);
-    }
-
-    #[test]
-    fn test_max() {
-        assert_eq!(1f32.max(&2f32), 2f32);
-        assert_eq!(2f32.max(&1f32), 2f32);
-    }
-
-    #[test]
-    fn test_clamp() {
-        assert_eq!(1f32.clamp(&2f32, &4f32), 2f32);
-        assert_eq!(8f32.clamp(&2f32, &4f32), 4f32);
-        assert_eq!(3f32.clamp(&2f32, &4f32), 3f32);
-
-        let nan: f32 = Float::nan();
-        assert!(3f32.clamp(&nan, &4f32).is_nan());
-        assert!(3f32.clamp(&2f32, &nan).is_nan());
-        assert!(nan.clamp(&2f32, &4f32).is_nan());
-    }
-
-    #[test]
     fn test_floor() {
         assert_approx_eq!(1.0f32.floor(), 1.0f32);
         assert_approx_eq!(1.3f32.floor(), 1.0f32);
diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs
index d51f6b602d7..643dcc5bd4b 100644
--- a/src/libstd/num/f64.rs
+++ b/src/libstd/num/f64.rs
@@ -196,42 +196,6 @@ impl Ord for f64 {
     fn gt(&self, other: &f64) -> bool { (*self) > (*other) }
 }
 
-impl Orderable for f64 {
-    /// Returns `NAN` if either of the numbers are `NAN`.
-    #[inline]
-    fn min(&self, other: &f64) -> f64 {
-        match () {
-            _ if self.is_nan()  => *self,
-            _ if other.is_nan() => *other,
-            _ if *self < *other => *self,
-            _                   => *other,
-        }
-    }
-
-    /// Returns `NAN` if either of the numbers are `NAN`.
-    #[inline]
-    fn max(&self, other: &f64) -> f64 {
-        match () {
-            _ if self.is_nan()  => *self,
-            _ if other.is_nan() => *other,
-            _ if *self > *other => *self,
-            _                   => *other,
-        }
-    }
-
-    /// Returns the number constrained within the range `mn <= self <= mx`.
-    /// If any of the numbers are `NAN` then `NAN` is returned.
-    #[inline]
-    fn clamp(&self, mn: &f64, mx: &f64) -> f64 {
-        match () {
-            _ if self.is_nan()   => *self,
-            _ if !(*self <= *mx) => *mx,
-            _ if !(*self >= *mn) => *mn,
-            _                    => *self,
-        }
-    }
-}
-
 impl Default for f64 {
     #[inline]
     fn default() -> f64 { 0.0 }
@@ -916,38 +880,6 @@ mod tests {
     }
 
     #[test]
-    fn test_min() {
-        assert_eq!(1f64.min(&2f64), 1f64);
-        assert_eq!(2f64.min(&1f64), 1f64);
-
-        let nan: f64 = Float::nan();
-        assert!(1f64.min(&nan).is_nan());
-        assert!(nan.min(&1f64).is_nan());
-    }
-
-    #[test]
-    fn test_max() {
-        assert_eq!(1f64.max(&2f64), 2f64);
-        assert_eq!(2f64.max(&1f64), 2f64);
-
-        let nan: f64 = Float::nan();
-        assert!(1f64.max(&nan).is_nan());
-        assert!(nan.max(&1f64).is_nan());
-    }
-
-    #[test]
-    fn test_clamp() {
-        assert_eq!(1f64.clamp(&2f64, &4f64), 2f64);
-        assert_eq!(8f64.clamp(&2f64, &4f64), 4f64);
-        assert_eq!(3f64.clamp(&2f64, &4f64), 3f64);
-
-        let nan: f64 = Float::nan();
-        assert!(3f64.clamp(&nan, &4f64).is_nan());
-        assert!(3f64.clamp(&2f64, &nan).is_nan());
-        assert!(nan.clamp(&2f64, &4f64).is_nan());
-    }
-
-    #[test]
     fn test_floor() {
         assert_approx_eq!(1.0f64.floor(), 1.0f64);
         assert_approx_eq!(1.3f64.floor(), 1.0f64);
diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs
index c8d5dc12499..4965d060611 100644
--- a/src/libstd/num/int_macros.rs
+++ b/src/libstd/num/int_macros.rs
@@ -53,24 +53,6 @@ impl Eq for $T {
     fn eq(&self, other: &$T) -> bool { return (*self) == (*other); }
 }
 
-impl Orderable for $T {
-    #[inline]
-    fn min(&self, other: &$T) -> $T {
-        if *self < *other { *self } else { *other }
-    }
-
-    #[inline]
-    fn max(&self, other: &$T) -> $T {
-        if *self > *other { *self } else { *other }
-    }
-
-    #[inline]
-    fn clamp(&self, mn: &$T, mx: &$T) -> $T {
-        if *self > *mx { *mx } else
-        if *self < *mn { *mn } else { *self }
-    }
-}
-
 impl Default for $T {
     #[inline]
     fn default() -> $T { 0 }
@@ -458,17 +440,6 @@ mod tests {
     }
 
     #[test]
-    fn test_orderable() {
-        assert_eq!((1 as $T).min(&(2 as $T)), 1 as $T);
-        assert_eq!((2 as $T).min(&(1 as $T)), 1 as $T);
-        assert_eq!((1 as $T).max(&(2 as $T)), 2 as $T);
-        assert_eq!((2 as $T).max(&(1 as $T)), 2 as $T);
-        assert_eq!((1 as $T).clamp(&(2 as $T), &(4 as $T)), 2 as $T);
-        assert_eq!((8 as $T).clamp(&(2 as $T), &(4 as $T)), 4 as $T);
-        assert_eq!((3 as $T).clamp(&(2 as $T), &(4 as $T)), 3 as $T);
-    }
-
-    #[test]
     pub fn test_abs() {
         assert_eq!((1 as $T).abs(), 1 as $T);
         assert_eq!((0 as $T).abs(), 0 as $T);
diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs
index 976761b5120..c5510078e39 100644
--- a/src/libstd/num/mod.rs
+++ b/src/libstd/num/mod.rs
@@ -33,23 +33,6 @@ pub trait Num: Eq + Zero + One
              + Div<Self,Self>
              + Rem<Self,Self> {}
 
-pub trait Orderable: Ord {
-    // These should be methods on `Ord`, with overridable default implementations. We don't want
-    // to encumber all implementors of Ord by requiring them to implement these functions, but at
-    // the same time we want to be able to take advantage of the speed of the specific numeric
-    // functions (like the `fmin` and `fmax` intrinsics).
-    fn min(&self, other: &Self) -> Self;
-    fn max(&self, other: &Self) -> Self;
-    fn clamp(&self, mn: &Self, mx: &Self) -> Self;
-}
-
-/// Return the smaller number.
-#[inline(always)] pub fn min<T: Orderable>(x: T, y: T) -> T { x.min(&y) }
-/// Return the larger number.
-#[inline(always)] pub fn max<T: Orderable>(x: T, y: T) -> T { x.max(&y) }
-/// Returns the number constrained within the range `mn <= self <= mx`.
-#[inline(always)] pub fn clamp<T: Orderable>(value: T, mn: T, mx: T) -> T { value.clamp(&mn, &mx) }
-
 /// Defines an additive identity element for `Self`.
 ///
 /// # Deriving
@@ -140,7 +123,7 @@ pub trait Signed: Num
 pub trait Unsigned: Num {}
 
 pub trait Integer: Num
-                 + Orderable
+                 + Ord
                  + Div<Self,Self>
                  + Rem<Self,Self> {
     fn div_rem(&self, other: &Self) -> (Self,Self);
@@ -185,7 +168,7 @@ pub trait Round {
 
 /// Defines constants and methods common to real numbers
 pub trait Real: Signed
-              + Orderable
+              + Ord
               + Round
               + Div<Self,Self> {
     // Common Constants
@@ -434,7 +417,7 @@ pub trait Primitive: Clone
                    + DeepClone
                    + Num
                    + NumCast
-                   + Orderable
+                   + Ord
                    + Bounded {}
 
 /// A collection of traits relevant to primitive signed and unsigned integers
diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs
index eb483843b5d..bbf1c497c2b 100644
--- a/src/libstd/num/uint_macros.rs
+++ b/src/libstd/num/uint_macros.rs
@@ -44,28 +44,6 @@ impl Eq for $T {
     fn eq(&self, other: &$T) -> bool { return (*self) == (*other); }
 }
 
-impl Orderable for $T {
-    #[inline]
-    fn min(&self, other: &$T) -> $T {
-        if *self < *other { *self } else { *other }
-    }
-
-    #[inline]
-    fn max(&self, other: &$T) -> $T {
-        if *self > *other { *self } else { *other }
-    }
-
-    /// Returns the number constrained within the range `mn <= self <= mx`.
-    #[inline]
-    fn clamp(&self, mn: &$T, mx: &$T) -> $T {
-        match () {
-            _ if (*self > *mx) => *mx,
-            _ if (*self < *mn) => *mn,
-            _                  => *self,
-        }
-    }
-}
-
 impl Default for $T {
     #[inline]
     fn default() -> $T { 0 }
@@ -330,17 +308,6 @@ mod tests {
     }
 
     #[test]
-    fn test_orderable() {
-        assert_eq!((1 as $T).min(&(2 as $T)), 1 as $T);
-        assert_eq!((2 as $T).min(&(1 as $T)), 1 as $T);
-        assert_eq!((1 as $T).max(&(2 as $T)), 2 as $T);
-        assert_eq!((2 as $T).max(&(1 as $T)), 2 as $T);
-        assert_eq!((1 as $T).clamp(&(2 as $T), &(4 as $T)), 2 as $T);
-        assert_eq!((8 as $T).clamp(&(2 as $T), &(4 as $T)), 4 as $T);
-        assert_eq!((3 as $T).clamp(&(2 as $T), &(4 as $T)), 3 as $T);
-    }
-
-    #[test]
     fn test_div_mod_floor() {
         assert_eq!((10 as $T).div_floor(&(3 as $T)), 3 as $T);
         assert_eq!((10 as $T).mod_floor(&(3 as $T)), 1 as $T);