]> git.lizzy.rs Git - rust.git/commitdiff
Removed num::Orderable
authorMichael Darakananda <pongad@gmail.com>
Thu, 6 Feb 2014 07:34:33 +0000 (02:34 -0500)
committerMichael Darakananda <pongad@gmail.com>
Fri, 14 Feb 2014 01:12:59 +0000 (20:12 -0500)
26 files changed:
src/libarena/lib.rs
src/libcollections/bitv.rs
src/libcollections/ringbuf.rs
src/libextra/test.rs
src/libglob/lib.rs
src/libnum/bigint.rs
src/libnum/rational.rs
src/librustc/lib.rs
src/librustc/metadata/loader.rs
src/librustc/middle/check_match.rs
src/librustc/middle/trans/cabi_arm.rs
src/librustc/middle/trans/cabi_mips.rs
src/librustc/middle/trans/cabi_x86_64.rs
src/librustdoc/passes.rs
src/libstd/cmp.rs
src/libstd/hashmap.rs
src/libstd/io/buffered.rs
src/libstd/num/f32.rs
src/libstd/num/f64.rs
src/libstd/num/int_macros.rs
src/libstd/num/mod.rs
src/libstd/num/uint_macros.rs
src/libstd/prelude.rs
src/libsyntax/ast_util.rs
src/test/bench/shootout-fasta.rs
src/test/bench/shootout-spectralnorm.rs

index b41af9eb05430f19cbcc72c8fae978b5d069a01c..6639e7b3ab7d2fdd759237b75d0747ca7d668350 100644 (file)
@@ -33,6 +33,7 @@
 use std::cast;
 use std::cell::{Cell, RefCell};
 use std::mem;
+use std::cmp;
 use std::num;
 use std::kinds::marker;
 use std::rc::Rc;
@@ -183,7 +184,7 @@ fn chunk_size(&self) -> uint {
     // Functions for the POD part of the arena
     fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 {
         // Allocate a new chunk.
-        let new_min_chunk_size = num::max(n_bytes, self.chunk_size());
+        let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
         self.chunks.set(@Cons(self.pod_head.clone(), self.chunks.get()));
         self.pod_head =
             chunk(num::next_power_of_two(new_min_chunk_size + 1u), true);
@@ -223,7 +224,7 @@ fn alloc_pod<'a, T>(&'a mut self, op: || -> T) -> &'a T {
     fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint)
                          -> (*u8, *u8) {
         // Allocate a new chunk.
-        let new_min_chunk_size = num::max(n_bytes, self.chunk_size());
+        let new_min_chunk_size = cmp::max(n_bytes, self.chunk_size());
         self.chunks.set(@Cons(self.head.clone(), self.chunks.get()));
         self.head =
             chunk(num::next_power_of_two(new_min_chunk_size + 1u), false);
index 7211907f483212578caaa14049ff69b10e7ffb48..1ff868dced20e5addf987aa6c155eccf4d37d1f7 100644 (file)
@@ -14,7 +14,6 @@
 use std::cmp;
 use std::iter::RandomAccessIterator;
 use std::iter::{Rev, Enumerate, Repeat, Map, Zip};
-use std::num;
 use std::ops;
 use std::uint;
 use std::vec;
@@ -846,7 +845,7 @@ fn insert(&mut self, value: uint) -> bool {
         }
         let nbits = self.capacity();
         if value >= nbits {
-            let newsize = num::max(value, nbits * 2) / uint::BITS + 1;
+            let newsize = cmp::max(value, nbits * 2) / uint::BITS + 1;
             assert!(newsize > self.bitv.storage.len());
             self.bitv.storage.grow(newsize, &0);
         }
@@ -881,7 +880,7 @@ impl BitvSet {
     fn commons<'a>(&'a self, other: &'a BitvSet)
         -> Map<'static, ((uint, &'a uint), &'a ~[uint]), (uint, uint, uint),
                Zip<Enumerate<vec::Items<'a, uint>>, Repeat<&'a ~[uint]>>> {
-        let min = num::min(self.bitv.storage.len(), other.bitv.storage.len());
+        let min = cmp::min(self.bitv.storage.len(), other.bitv.storage.len());
         self.bitv.storage.slice(0, min).iter().enumerate()
             .zip(Repeat::new(&other.bitv.storage))
             .map(|((i, &w), o_store)| (i * uint::BITS, w, o_store[i]))
index 933fe2048e44553e1221a4c4149785d442141d4b..325f55b463451dc81dc4e6f0a3860e4bdb0b0e4a 100644 (file)
@@ -13,7 +13,7 @@
 //! RingBuf implements the trait Deque. It should be imported with `use
 //! extra::container::Deque`.
 
-use std::num;
+use std::cmp;
 use std::vec;
 use std::iter::{Rev, RandomAccessIterator};
 
@@ -120,7 +120,7 @@ pub fn new() -> RingBuf<T> {
     /// Create an empty RingBuf with space for at least `n` elements.
     pub fn with_capacity(n: uint) -> RingBuf<T> {
         RingBuf{nelts: 0, lo: 0,
-              elts: vec::from_fn(num::max(MINIMUM_CAPACITY, n), |_| None)}
+              elts: vec::from_fn(cmp::max(MINIMUM_CAPACITY, n), |_| None)}
     }
 
     /// Retrieve an element in the RingBuf by index
index 9ebd91bdfb6cd538d0fbc2b9d12c43c3824e8438..85da41911c93dab7a233c740b75fc578c964b2df 100644 (file)
@@ -27,6 +27,7 @@
 use collections::TreeMap;
 
 use std::clone::Clone;
+use std::cmp;
 use std::io;
 use std::io::File;
 use std::io::Writer;
@@ -1003,7 +1004,7 @@ pub fn compare_to_old(&self, old: &MetricMap,
                     if delta.abs() <= noise {
                         LikelyNoise
                     } else {
-                        let pct = delta.abs() / (vold.value).max(&f64::EPSILON) * 100.0;
+                        let pct = delta.abs() / cmp::max(vold.value, f64::EPSILON) * 100.0;
                         if vold.noise < 0.0 {
                             // When 'noise' is negative, it means we want
                             // to see deltas that go up over time, and can
@@ -1126,7 +1127,7 @@ pub fn ns_per_iter(&mut self) -> u64 {
         if self.iterations == 0 {
             0
         } else {
-            self.ns_elapsed() / self.iterations.max(&1)
+            self.ns_elapsed() / cmp::max(self.iterations, 1)
         }
     }
 
@@ -1149,7 +1150,7 @@ pub fn auto_bench(&mut self, f: |&mut BenchHarness|) -> stats::Summary {
         if self.ns_per_iter() == 0 {
             n = 1_000_000;
         } else {
-            n = 1_000_000 / self.ns_per_iter().max(&1);
+            n = 1_000_000 / cmp::max(self.ns_per_iter(), 1);
         }
         // if the first run took more than 1ms we don't want to just
         // be left doing 0 iterations on every loop. The unfortunate
@@ -1215,6 +1216,7 @@ pub fn auto_bench(&mut self, f: |&mut BenchHarness|) -> stats::Summary {
 }
 
 pub mod bench {
+    use std::cmp;
     use test::{BenchHarness, BenchSamples};
 
     pub fn benchmark(f: |&mut BenchHarness|) -> BenchSamples {
@@ -1227,7 +1229,7 @@ pub fn benchmark(f: |&mut BenchHarness|) -> BenchSamples {
 
         let ns_iter_summ = bs.auto_bench(f);
 
-        let ns_iter = (ns_iter_summ.median as u64).max(&1);
+        let ns_iter = cmp::max(ns_iter_summ.median as u64, 1);
         let iter_s = 1_000_000_000 / ns_iter;
         let mb_s = (bs.bytes * iter_s) / 1_000_000;
 
index 25634b1808de2d608f33bd926f93c304025f31ee..cb6f5b24a0943eb562601091e139fff20dcf67be 100644 (file)
@@ -29,7 +29,7 @@
 #[license = "MIT/ASL2"];
 
 use std::cell::Cell;
-use std::{os, path};
+use std::{cmp, os, path};
 use std::io::fs;
 use std::path::is_sep;
 
@@ -106,7 +106,7 @@ fn check_windows_verbatim(_: &Path) -> bool { false }
     }
 
     let root_len = pat_root.map_or(0u, |p| p.as_vec().len());
-    let dir_patterns = pattern.slice_from(root_len.min(&pattern.len()))
+    let dir_patterns = pattern.slice_from(cmp::min(root_len, pattern.len()))
                        .split_terminator(is_sep).map(|s| Pattern::new(s)).to_owned_vec();
 
     let todo = list_dir_sorted(&root).move_iter().map(|x|(x,0u)).to_owned_vec();
index 8f632ae639dcca61f11e728fb0f330f476e6537a..345dce12feda785743c0c3efac09d9168f80a3b6 100644 (file)
@@ -16,9 +16,9 @@
 A `BigInt` is a combination of `BigUint` and `Sign`.
 */
 
+use std::cmp;
 use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
-use std::num;
-use std::num::{Zero, One, ToStrRadix, FromStrRadix, Orderable};
+use std::num::{Zero, One, ToStrRadix, FromStrRadix};
 use std::num::{Bitwise, ToPrimitive, FromPrimitive};
 use std::rand::Rng;
 use std::str;
@@ -133,27 +133,9 @@ fn from_str(s: &str) -> Option<BigUint> {
 
 impl Num for BigUint {}
 
-impl Orderable for BigUint {
-    #[inline]
-    fn min(&self, other: &BigUint) -> BigUint {
-        if self < other { self.clone() } else { other.clone() }
-    }
-
-    #[inline]
-    fn max(&self, other: &BigUint) -> BigUint {
-        if self > other { self.clone() } else { other.clone() }
-    }
-
-    #[inline]
-    fn clamp(&self, mn: &BigUint, mx: &BigUint) -> BigUint {
-        if self > mx { mx.clone() } else
-        if self < mn { mn.clone() } else { self.clone() }
-    }
-}
-
 impl BitAnd<BigUint, BigUint> for BigUint {
     fn bitand(&self, other: &BigUint) -> BigUint {
-        let new_len = num::min(self.data.len(), other.data.len());
+        let new_len = cmp::min(self.data.len(), other.data.len());
         let anded = vec::from_fn(new_len, |i| {
             // i will never be less than the size of either data vector
             let ai = self.data[i];
@@ -166,7 +148,7 @@ fn bitand(&self, other: &BigUint) -> BigUint {
 
 impl BitOr<BigUint, BigUint> for BigUint {
     fn bitor(&self, other: &BigUint) -> BigUint {
-        let new_len = num::max(self.data.len(), other.data.len());
+        let new_len = cmp::max(self.data.len(), other.data.len());
         let ored = vec::from_fn(new_len, |i| {
             let ai = if i < self.data.len()  { self.data[i]  } else { 0 };
             let bi = if i < other.data.len() { other.data[i] } else { 0 };
@@ -178,7 +160,7 @@ fn bitor(&self, other: &BigUint) -> BigUint {
 
 impl BitXor<BigUint, BigUint> for BigUint {
     fn bitxor(&self, other: &BigUint) -> BigUint {
-        let new_len = num::max(self.data.len(), other.data.len());
+        let new_len = cmp::max(self.data.len(), other.data.len());
         let xored = vec::from_fn(new_len, |i| {
             let ai = if i < self.data.len()  { self.data[i]  } else { 0 };
             let bi = if i < other.data.len() { other.data[i] } else { 0 };
@@ -223,7 +205,7 @@ impl Unsigned for BigUint {}
 
 impl Add<BigUint, BigUint> for BigUint {
     fn add(&self, other: &BigUint) -> BigUint {
-        let new_len = num::max(self.data.len(), other.data.len());
+        let new_len = cmp::max(self.data.len(), other.data.len());
 
         let mut carry = 0;
         let mut sum = vec::from_fn(new_len, |i| {
@@ -242,7 +224,7 @@ fn add(&self, other: &BigUint) -> BigUint {
 
 impl Sub<BigUint, BigUint> for BigUint {
     fn sub(&self, other: &BigUint) -> BigUint {
-        let new_len = num::max(self.data.len(), other.data.len());
+        let new_len = cmp::max(self.data.len(), other.data.len());
 
         let mut borrow = 0;
         let diff = vec::from_fn(new_len, |i| {
@@ -278,7 +260,7 @@ fn mul(&self, other: &BigUint) -> BigUint {
         // = a1*b1 * base^2 +
         //   (a1*b1 + a0*b0 - (a1-b0)*(b1-a0)) * base +
         //   a0*b0
-        let half_len = num::max(s_len, o_len) / 2;
+        let half_len = cmp::max(s_len, o_len) / 2;
         let (sHi, sLo) = cut_at(self,  half_len);
         let (oHi, oLo) = cut_at(other, half_len);
 
@@ -315,7 +297,7 @@ fn mul_digit(a: &BigUint, n: BigDigit) -> BigUint {
 
         #[inline]
         fn cut_at(a: &BigUint, n: uint) -> (BigUint, BigUint) {
-            let mid = num::min(a.data.len(), n);
+            let mid = cmp::min(a.data.len(), n);
             return (BigUint::from_slice(a.data.slice(mid, a.data.len())),
                     BigUint::from_slice(a.data.slice(0, mid)));
         }
@@ -720,7 +702,7 @@ pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<BigUint> {
         let mut n: BigUint      = Zero::zero();
         let mut power: BigUint  = One::one();
         loop {
-            let start = num::max(end, unit_len) - unit_len;
+            let start = cmp::max(end, unit_len) - unit_len;
             match uint::parse_bytes(buf.slice(start, end), radix) {
                 Some(d) => {
                     let d: Option<BigUint> = FromPrimitive::from_uint(d);
@@ -941,24 +923,6 @@ fn from_str(s: &str) -> Option<BigInt> {
 
 impl Num for BigInt {}
 
-impl Orderable for BigInt {
-    #[inline]
-    fn min(&self, other: &BigInt) -> BigInt {
-        if self < other { self.clone() } else { other.clone() }
-    }
-
-    #[inline]
-    fn max(&self, other: &BigInt) -> BigInt {
-        if self > other { self.clone() } else { other.clone() }
-    }
-
-    #[inline]
-    fn clamp(&self, mn: &BigInt, mx: &BigInt) -> BigInt {
-        if self > mx { mx.clone() } else
-        if self < mn { mn.clone() } else { self.clone() }
-    }
-}
-
 impl Shl<uint, BigInt> for BigInt {
     #[inline]
     fn shl(&self, rhs: &uint) -> BigInt {
index 698a109a756164184130c839dd50ab4aac15be9e..a41996d044f82db877f9fa611658c29ca92e6d5e 100644 (file)
@@ -160,25 +160,6 @@ fn $method(&self, other: &Ratio<T>) -> $res {
 cmp_impl!(impl Ord, lt, gt, le, ge)
 cmp_impl!(impl TotalOrd, cmp -> cmp::Ordering)
 
-impl<T: Clone + Integer + Ord> Orderable for Ratio<T> {
-    #[inline]
-    fn min(&self, other: &Ratio<T>) -> Ratio<T> {
-        if *self < *other { self.clone() } else { other.clone() }
-    }
-
-    #[inline]
-    fn max(&self, other: &Ratio<T>) -> Ratio<T> {
-        if *self > *other { self.clone() } else { other.clone() }
-    }
-
-    #[inline]
-    fn clamp(&self, mn: &Ratio<T>, mx: &Ratio<T>) -> Ratio<T> {
-        if *self > *mx { mx.clone()} else
-        if *self < *mn { mn.clone() } else { self.clone() }
-    }
-}
-
-
 /* Arithmetic */
 // a/b * c/d = (a*c)/(b*d)
 impl<T: Clone + Integer + Ord>
index 9cd93df6fa3a13975b17332dac801ee59f3fe8fb..05087581fd73ae3cdd24164ab2673a095a844b0d 100644 (file)
@@ -46,8 +46,8 @@
 
 use d = driver::driver;
 
+use std::cmp;
 use std::io;
-use std::num;
 use std::os;
 use std::str;
 use std::task;
@@ -164,7 +164,7 @@ pub fn describe_warnings() {
 
     let mut max_key = 0;
     for &(_, name) in lint_dict.iter() {
-        max_key = num::max(name.len(), max_key);
+        max_key = cmp::max(name.len(), max_key);
     }
     fn padded(max: uint, s: &str) -> ~str {
         " ".repeat(max - s.len()) + s
index 70b93a9813535842c5791b7e16697395b18a3102..8e704aa14da4f802b09e8ca7bafe28acf2d93317 100644 (file)
@@ -26,8 +26,8 @@
 
 use std::c_str::ToCStr;
 use std::cast;
+use std::cmp;
 use std::io;
-use std::num;
 use std::option;
 use std::os::consts::{macos, freebsd, linux, android, win32};
 use std::str;
@@ -331,7 +331,7 @@ fn get_metadata_section_imp(os: Os, filename: &Path) -> Option<MetadataBlob> {
                 let vlen = encoder::metadata_encoding_version.len();
                 debug!("checking {} bytes of metadata-version stamp",
                        vlen);
-                let minsz = num::min(vlen, csz);
+                let minsz = cmp::min(vlen, csz);
                 let mut version_ok = false;
                 vec::raw::buf_as_slice(cvbuf, minsz, |buf0| {
                     version_ok = (buf0 ==
index ab9eff3a372c62ea20eba32fd20f9320f3e94615..0ddbfc3b538a8e534fa00253eed25b2ed6275e2b 100644 (file)
@@ -18,8 +18,8 @@
 use middle::moves;
 use util::ppaux::ty_to_str;
 
+use std::cmp;
 use std::iter;
-use std::num;
 use std::vec;
 use syntax::ast::*;
 use syntax::ast_util::{unguarded_pat, walk_pat};
@@ -286,7 +286,7 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
                 let max_len = m.rev_iter().fold(0, |max_len, r| {
                   match r[0].node {
                     PatVec(ref before, _, ref after) => {
-                      num::max(before.len() + after.len(), max_len)
+                      cmp::max(before.len() + after.len(), max_len)
                     }
                     _ => max_len
                   }
index a73c098805d6a9898910110252c18beb43ad41fd..ca80ce26ae3962b0ff33dccb4a7f01f0b999da62 100644 (file)
@@ -17,7 +17,7 @@
 
 use middle::trans::type_::Type;
 
-use std::num;
+use std::cmp;
 use std::option::{None, Some};
 
 fn align_up_to(off: uint, a: uint) -> uint {
@@ -44,7 +44,7 @@ fn ty_align(ty: Type) -> uint {
                 1
             } else {
                 let str_tys = ty.field_types();
-                str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
+                str_tys.iter().fold(1, |a, t| cmp::max(a, ty_align(*t)))
             }
         }
         Array => {
index 54155cd3f7825f05aa7ceed61f6abdb2c7f88dc5..c3bd84dd583ad5c02e9738fe90c3187be449318d 100644 (file)
@@ -11,7 +11,7 @@
 #[allow(non_uppercase_pattern_statics)];
 
 use std::libc::c_uint;
-use std::num;
+use std::cmp;
 use lib::llvm::{llvm, Integer, Pointer, Float, Double, Struct, Array};
 use lib::llvm::StructRetAttribute;
 use middle::trans::context::CrateContext;
@@ -44,7 +44,7 @@ fn ty_align(ty: Type) -> uint {
             1
           } else {
             let str_tys = ty.field_types();
-            str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
+            str_tys.iter().fold(1, |a, t| cmp::max(a, ty_align(*t)))
           }
         }
         Array => {
@@ -98,7 +98,7 @@ fn classify_arg_ty(ty: Type, offset: &mut uint) -> ArgType {
     let size = ty_size(ty) * 8;
     let mut align = ty_align(ty);
 
-    align = num::min(num::max(align, 4), 8);
+    align = cmp::min(cmp::max(align, 4), 8);
     *offset = align_up_to(*offset, align);
     *offset += align_up_to(size, align * 8) / 8;
 
index 564efa8c06864770cebfe9bacefb1aeac04a4770..4d2e0eeb4762eee0cf2b0871f3af10bfdf6d7da9 100644 (file)
@@ -21,7 +21,7 @@
 
 use middle::trans::type_::Type;
 
-use std::num;
+use std::cmp;
 use std::vec;
 
 #[deriving(Clone, Eq)]
@@ -105,7 +105,7 @@ fn ty_align(ty: Type) -> uint {
                 1
               } else {
                 let str_tys = ty.field_types();
-                str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t)))
+                str_tys.iter().fold(1, |a, t| cmp::max(a, ty_align(*t)))
               }
             }
             Array => {
index 53b42baf402a74302b3d3d09f201c92e05a131e6..378e0c2f0ccaaea64f2a209d7e6a1254a1f66399 100644 (file)
@@ -8,9 +8,9 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use std::cmp;
 use std::hashmap::HashSet;
 use std::local_data;
-use std::num;
 use std::uint;
 use syntax::ast;
 
@@ -267,7 +267,7 @@ pub fn unindent(s: &str) -> ~str {
                     false
                 }
             });
-            num::min(min_indent, spaces)
+            cmp::min(min_indent, spaces)
         }
     });
 
index 1283aba9729b9775092a8684ef9825344852566d..de9f836ca5eb60a40543828d5fab0f54b5d36527 100644 (file)
@@ -169,6 +169,8 @@ fn le(&self, other: &Self) -> bool { !other.lt(self) }
     fn gt(&self, other: &Self) -> bool {  other.lt(self) }
     #[inline]
     fn ge(&self, other: &Self) -> bool { !self.lt(other) }
+
+    // FIXME (#12068): Add min/max/clamp default methods
 }
 
 /// The equivalence relation. Two values may be equivalent even if they are
index c49294a095f292d4cf05e556c7c72b9ff4eab5f3..f8e02c82fcd992e51854ccd7e48deae2d05758c8 100644 (file)
@@ -54,7 +54,7 @@
 
 use container::{Container, Mutable, Map, MutableMap, Set, MutableSet};
 use clone::Clone;
-use cmp::{Eq, Equiv};
+use cmp::{Eq, Equiv, max};
 use default::Default;
 #[cfg(not(stage0))] use fmt;
 use hash::Hash;
@@ -376,7 +376,7 @@ pub fn with_capacity(capacity: uint) -> HashMap<K, V> {
     /// cause many collisions and very poor performance. Setting them
     /// manually using this function can expose a DoS attack vector.
     pub fn with_capacity_and_keys(k0: u64, k1: u64, capacity: uint) -> HashMap<K, V> {
-        let cap = num::max(INITIAL_CAPACITY, capacity);
+        let cap = max(INITIAL_CAPACITY, capacity);
         HashMap {
             k0: k0, k1: k1,
             resize_at: resize_at(cap),
index a48403f19a4804a73a6c79e9704b473554de969e..231cf6592eb2ca907dd20f4ba4a2863586c8d4b3 100644 (file)
 
 //! Buffering wrappers for I/O traits
 
+use cmp;
 use container::Container;
 use io::{Reader, Writer, Stream, Buffer, DEFAULT_BUF_SIZE, IoResult};
 use iter::ExactSize;
-use num;
 use option::{Some, None};
 use result::{Ok, Err};
 use vec::{OwnedVector, ImmutableVector, MutableVector};
@@ -104,7 +104,7 @@ impl<R: Reader> Reader for BufferedReader<R> {
     fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
         let nread = {
             let available = if_ok!(self.fill());
-            let nread = num::min(available.len(), buf.len());
+            let nread = cmp::min(available.len(), buf.len());
             vec::bytes::copy_memory(buf, available.slice_to(nread));
             nread
         };
index a4b6aca86f7f15e6040091bd4290be9815dc5649..9951405fa0c2fad406cbd397a9a55742485c1453 100644 (file)
@@ -189,42 +189,6 @@ fn ge(&self, other: &f32) -> bool { (*self) >= (*other) }
     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 @@ fn test_num() {
         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);
index d51f6b602d72b73d69fd770d89d2f1eec2221865..643dcc5bd4b8e701b2a0a425901c51382577e71e 100644 (file)
@@ -196,42 +196,6 @@ fn ge(&self, other: &f64) -> bool { (*self) >= (*other) }
     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 @@ fn test_num() {
         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);
index c8d5dc1249959fb216a293c571a01170433d94ea..4965d0606115d43012a6ee42811b688a0374ac2d 100644 (file)
@@ -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 @@ fn test_num() {
         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);
index 976761b512053309e698a261e96fd717bd907f67..c5510078e39513c9b9e9b673c820fa4149db457f 100644 (file)
@@ -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
index eb483843b5dc28adf77c7fc5357505835553f51a..bbf1c497c2be556535fbccce9457cea0ab606d96 100644 (file)
@@ -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 @@ fn test_num() {
         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);
index 4849b83037f09b3367dd6aff85605300941c6b79..3eaa1db87bafdc7464f06231190df99b4372fc30 100644 (file)
@@ -59,7 +59,7 @@
 pub use iter::{Iterator, DoubleEndedIterator, RandomAccessIterator, CloneableIterator};
 pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize};
 pub use num::{Integer, Real, Num, NumCast, CheckedAdd, CheckedSub, CheckedMul};
-pub use num::{Orderable, Signed, Unsigned, Round};
+pub use num::{Signed, Unsigned, Round};
 pub use num::{Primitive, Int, Float, ToStrRadix, ToPrimitive, FromPrimitive};
 pub use path::{GenericPath, Path, PosixPath, WindowsPath};
 pub use ptr::RawPtr;
index afedb62105ba7e80766d5a73f11369da4ec71cbf..04051b749522d8014add473d6c592cf4709e1c8d 100644 (file)
 use visit;
 
 use std::cell::{Cell, RefCell};
+use std::cmp;
 use std::hashmap::HashMap;
 use std::u32;
 use std::local_data;
-use std::num;
 
 pub fn path_name_i(idents: &[Ident]) -> ~str {
     // FIXME: Bad copies (#2543 -- same for everything else that says "bad")
@@ -343,8 +343,8 @@ pub fn empty(&self) -> bool {
     }
 
     pub fn add(&mut self, id: NodeId) {
-        self.min = num::min(self.min, id);
-        self.max = num::max(self.max, id + 1);
+        self.min = cmp::min(self.min, id);
+        self.max = cmp::max(self.max, id + 1);
     }
 }
 
index 74d8af52f7d7ae3fca5b55f3bbe02490881e4483..12e78629386259b6de999fefe65c8ab684aae366 100644 (file)
@@ -16,7 +16,7 @@
 
 use std::io;
 use std::io::{BufferedWriter, File};
-use std::num::min;
+use std::cmp::min;
 use std::os;
 
 static LINE_LENGTH: uint = 60;
index 96883dd4e21bb1bdbc91dcf5256adf29bc01afe3..a6e6713e137b11d47fba1b67b4aad51a72e87eaa 100644 (file)
@@ -14,7 +14,7 @@
 
 use std::from_str::FromStr;
 use std::iter::count;
-use std::num::min;
+use std::cmp::min;
 use std::os;
 use std::vec::from_elem;
 use sync::Arc;