From bf1464c413bb2564c7be0eaceef9515bc0f94f1f Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Thu, 6 Feb 2014 02:34:33 -0500 Subject: Removed num::Orderable --- src/libstd/num/f32.rs | 60 -------------------------------------- src/libstd/num/f64.rs | 68 ------------------------------------------- src/libstd/num/int_macros.rs | 29 ------------------ src/libstd/num/mod.rs | 23 ++------------- src/libstd/num/uint_macros.rs | 33 --------------------- 5 files changed, 3 insertions(+), 210 deletions(-) (limited to 'src/libstd/num') 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 } @@ -913,30 +877,6 @@ mod tests { num::test_num(10f32, 2f32); } - #[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); 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 } @@ -915,38 +879,6 @@ mod tests { num::test_num(10f64, 2f64); } - #[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); 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 } @@ -457,17 +439,6 @@ mod tests { num::test_num(10 as $T, 2 as $T); } - #[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); 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 + Rem {} -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(x: T, y: T) -> T { x.min(&y) } -/// Return the larger number. -#[inline(always)] pub fn max(x: T, y: T) -> T { x.max(&y) } -/// Returns the number constrained within the range `mn <= self <= mx`. -#[inline(always)] pub fn clamp(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 + Rem { 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 { // 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 } @@ -329,17 +307,6 @@ mod tests { num::test_num(10 as $T, 2 as $T); } - #[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); -- cgit 1.4.1-3-g733a5