From bf1464c413bb2564c7be0eaceef9515bc0f94f1f Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Thu, 6 Feb 2014 02:34:33 -0500 Subject: [PATCH] Removed num::Orderable --- src/libarena/lib.rs | 5 +- src/libcollections/bitv.rs | 5 +- src/libcollections/ringbuf.rs | 4 +- src/libextra/test.rs | 10 ++-- src/libglob/lib.rs | 4 +- src/libnum/bigint.rs | 56 ++++--------------- src/libnum/rational.rs | 19 ------- src/librustc/lib.rs | 4 +- src/librustc/metadata/loader.rs | 4 +- src/librustc/middle/check_match.rs | 4 +- src/librustc/middle/trans/cabi_arm.rs | 4 +- src/librustc/middle/trans/cabi_mips.rs | 6 +-- src/librustc/middle/trans/cabi_x86_64.rs | 4 +- src/librustdoc/passes.rs | 4 +- src/libstd/cmp.rs | 2 + src/libstd/hashmap.rs | 4 +- src/libstd/io/buffered.rs | 4 +- 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 ------------ src/libstd/prelude.rs | 2 +- src/libsyntax/ast_util.rs | 6 +-- src/test/bench/shootout-fasta.rs | 2 +- src/test/bench/shootout-spectralnorm.rs | 2 +- 26 files changed, 55 insertions(+), 313 deletions(-) diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index b41af9eb05430..6639e7b3ab7d2 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -33,6 +33,7 @@ use std::cast::{transmute, transmute_mut, transmute_mut_region}; 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 @@ impl Arena { // 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 @@ impl Arena { 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); diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index 7211907f48321..1ff868dced20e 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -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 @@ impl MutableSet for BitvSet { } 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>, 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])) diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs index 933fe2048e445..325f55b463451 100644 --- a/src/libcollections/ringbuf.rs +++ b/src/libcollections/ringbuf.rs @@ -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 @@ impl RingBuf { /// Create an empty RingBuf with space for at least `n` elements. pub fn with_capacity(n: uint) -> RingBuf { 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 diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 9ebd91bdfb6cd..85da41911c93d 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -27,6 +27,7 @@ use time::precise_time_ns; 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 @@ impl 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 @@ impl BenchHarness { 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 @@ impl BenchHarness { 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 @@ impl BenchHarness { } pub mod bench { + use std::cmp; use test::{BenchHarness, BenchSamples}; pub fn benchmark(f: |&mut BenchHarness|) -> BenchSamples { @@ -1227,7 +1229,7 @@ pub mod bench { 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; diff --git a/src/libglob/lib.rs b/src/libglob/lib.rs index 25634b1808de2..cb6f5b24a0943 100644 --- a/src/libglob/lib.rs +++ b/src/libglob/lib.rs @@ -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 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths { } 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(); diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index 8f632ae639dcc..345dce12feda7 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -16,9 +16,9 @@ A `BigUint` is represented as an array of `BigDigit`s. 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 @@ impl FromStr for 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 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 @@ impl BitAnd for BigUint { impl BitOr 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 @@ impl BitOr for BigUint { impl BitXor 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 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 @@ impl Add for BigUint { impl Sub 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 @@ impl Mul for 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 @@ impl Mul for 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 @@ impl 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 = FromPrimitive::from_uint(d); @@ -941,24 +923,6 @@ impl FromStr for 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 for BigInt { #[inline] fn shl(&self, rhs: &uint) -> BigInt { diff --git a/src/libnum/rational.rs b/src/libnum/rational.rs index 698a109a75616..a41996d044f82 100644 --- a/src/libnum/rational.rs +++ b/src/libnum/rational.rs @@ -160,25 +160,6 @@ cmp_impl!(impl TotalEq, equals) cmp_impl!(impl Ord, lt, gt, le, ge) cmp_impl!(impl TotalOrd, cmp -> cmp::Ordering) -impl Orderable for Ratio { - #[inline] - fn min(&self, other: &Ratio) -> Ratio { - if *self < *other { self.clone() } else { other.clone() } - } - - #[inline] - fn max(&self, other: &Ratio) -> Ratio { - if *self > *other { self.clone() } else { other.clone() } - } - - #[inline] - fn clamp(&self, mn: &Ratio, mx: &Ratio) -> Ratio { - if *self > *mx { mx.clone()} else - if *self < *mn { mn.clone() } else { self.clone() } - } -} - - /* Arithmetic */ // a/b * c/d = (a*c)/(b*d) impl diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 9cd93df6fa3a1..05087581fd73a 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -46,8 +46,8 @@ use middle::lint; 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 @@ Available lint options: 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 diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 70b93a9813535..8e704aa14da4f 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -26,8 +26,8 @@ use syntax::attr::AttrMetaMethods; 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 { 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 == diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index ab9eff3a372c6..0ddbfc3b538a8 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -18,8 +18,8 @@ use middle::typeck::method_map; 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 } diff --git a/src/librustc/middle/trans/cabi_arm.rs b/src/librustc/middle/trans/cabi_arm.rs index a73c098805d6a..ca80ce26ae396 100644 --- a/src/librustc/middle/trans/cabi_arm.rs +++ b/src/librustc/middle/trans/cabi_arm.rs @@ -17,7 +17,7 @@ use middle::trans::context::CrateContext; 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 => { diff --git a/src/librustc/middle/trans/cabi_mips.rs b/src/librustc/middle/trans/cabi_mips.rs index 54155cd3f7825..c3bd84dd583ad 100644 --- a/src/librustc/middle/trans/cabi_mips.rs +++ b/src/librustc/middle/trans/cabi_mips.rs @@ -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; diff --git a/src/librustc/middle/trans/cabi_x86_64.rs b/src/librustc/middle/trans/cabi_x86_64.rs index 564efa8c06864..4d2e0eeb4762e 100644 --- a/src/librustc/middle/trans/cabi_x86_64.rs +++ b/src/librustc/middle/trans/cabi_x86_64.rs @@ -21,7 +21,7 @@ use middle::trans::context::CrateContext; use middle::trans::type_::Type; -use std::num; +use std::cmp; use std::vec; #[deriving(Clone, Eq)] @@ -105,7 +105,7 @@ fn classify_ty(ty: Type) -> ~[RegClass] { 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 => { diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index 53b42baf402a7..378e0c2f0ccaa 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -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) } }); diff --git a/src/libstd/cmp.rs b/src/libstd/cmp.rs index 1283aba9729b9..de9f836ca5eb6 100644 --- a/src/libstd/cmp.rs +++ b/src/libstd/cmp.rs @@ -169,6 +169,8 @@ pub trait Ord { 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 diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index c49294a095f29..f8e02c82fcd99 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -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 @@ impl HashMap { /// 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 { - let cap = num::max(INITIAL_CAPACITY, capacity); + let cap = max(INITIAL_CAPACITY, capacity); HashMap { k0: k0, k1: k1, resize_at: resize_at(cap), diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index a48403f19a480..231cf6592eb2c 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -10,10 +10,10 @@ //! 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 Reader for BufferedReader { fn read(&mut self, buf: &mut [u8]) -> IoResult { 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 }; diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index a4b6aca86f7f1..9951405fa0c2f 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 d51f6b602d72b..643dcc5bd4b8e 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 c8d5dc1249959..4965d0606115d 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 976761b512053..c5510078e3951 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 eb483843b5dc2..bbf1c497c2be5 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); diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 4849b83037f09..3eaa1db87bafd 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -59,7 +59,7 @@ pub use iter::{FromIterator, Extendable}; 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; diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index afedb62105ba7..04051b749522d 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -18,10 +18,10 @@ use visit::Visitor; 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 @@ impl IdRange { } 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); } } diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index 74d8af52f7d7a..12e7862938625 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -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; diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index 96883dd4e21bb..a6e6713e137b1 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -14,7 +14,7 @@ extern mod sync; 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;