diff --git a/doc/rust.md b/doc/rust.md index 42a010b114ab2..0a640648222b0 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -802,11 +802,11 @@ Use declarations support a number of convenient shortcuts: An example of `use` declarations: ~~~~ -use std::float::sin; +use std::num::sin; use std::option::{Some, None}; fn main() { - // Equivalent to 'info!(std::float::sin(1.0));' + // Equivalent to 'info!(std::num::sin(1.0));' info!(sin(1.0)); // Equivalent to 'info!(~[std::option::Some(1.0), std::option::None]);' diff --git a/doc/tutorial.md b/doc/tutorial.md index c8280a991827e..b282679b1a1d4 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -503,12 +503,13 @@ types. ~~~~ # use std::float; +# use std::num::atan; fn angle(vector: (float, float)) -> float { let pi = float::consts::pi; match vector { (0f, y) if y < 0f => 1.5 * pi, (0f, y) => 0.5 * pi, - (x, y) => float::atan(y / x) + (x, y) => atan(y / x) } } ~~~~ @@ -1728,10 +1729,9 @@ To call such a method, just prefix it with the type name and a double colon: ~~~~ # use std::float::consts::pi; -# use std::float::sqrt; struct Circle { radius: float } impl Circle { - fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } } + fn new(area: float) -> Circle { Circle { radius: (area / pi).sqrt() } } } let c = Circle::new(42.5); ~~~~ @@ -1997,16 +1997,15 @@ implementation to use. ~~~~ # use std::float::consts::pi; -# use std::float::sqrt; trait Shape { fn new(area: float) -> Self; } struct Circle { radius: float } struct Square { length: float } impl Shape for Circle { - fn new(area: float) -> Circle { Circle { radius: sqrt(area / pi) } } + fn new(area: float) -> Circle { Circle { radius: (area / pi).sqrt() } } } impl Shape for Square { - fn new(area: float) -> Square { Square { length: sqrt(area) } } + fn new(area: float) -> Square { Square { length: (area).sqrt() } } } let area = 42.5; @@ -2154,14 +2153,13 @@ Now, we can implement `Circle` on a type only if we also implement `Shape`. ~~~~ # use std::float::consts::pi; -# use std::float::sqrt; # trait Shape { fn area(&self) -> float; } # trait Circle : Shape { fn radius(&self) -> float; } # struct Point { x: float, y: float } # fn square(x: float) -> float { x * x } struct CircleStruct { center: Point, radius: float } impl Circle for CircleStruct { - fn radius(&self) -> float { sqrt(self.area() / pi) } + fn radius(&self) -> float { (self.area() / pi).sqrt() } } impl Shape for CircleStruct { fn area(&self) -> float { pi * square(self.radius) } @@ -2190,12 +2188,11 @@ Likewise, supertrait methods may also be called on trait objects. ~~~ {.xfail-test} # use std::float::consts::pi; -# use std::float::sqrt; # trait Shape { fn area(&self) -> float; } # trait Circle : Shape { fn radius(&self) -> float; } # struct Point { x: float, y: float } # struct CircleStruct { center: Point, radius: float } -# impl Circle for CircleStruct { fn radius(&self) -> float { sqrt(self.area() / pi) } } +# impl Circle for CircleStruct { fn radius(&self) -> float { (self.area() / pi).sqrt() } } # impl Shape for CircleStruct { fn area(&self) -> float { pi * square(self.radius) } } let concrete = @CircleStruct{center:Point{x:3f,y:4f},radius:5f}; diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs index f378384c5645c..f137b573c5549 100644 --- a/src/libextra/arena.rs +++ b/src/libextra/arena.rs @@ -40,6 +40,7 @@ use list::{MutList, MutCons, MutNil}; use std::at_vec; use std::cast::{transmute, transmute_mut, transmute_mut_region}; use std::cast; +use std::num; use std::ptr; use std::sys; use std::uint; @@ -175,7 +176,7 @@ impl Arena { fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 { // Allocate a new chunk. let chunk_size = at_vec::capacity(self.pod_head.data); - let new_min_chunk_size = uint::max(n_bytes, chunk_size); + let new_min_chunk_size = num::max(n_bytes, chunk_size); self.chunks = @mut MutCons(copy self.pod_head, self.chunks); self.pod_head = chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true); @@ -217,7 +218,7 @@ impl Arena { -> (*u8, *u8) { // Allocate a new chunk. let chunk_size = at_vec::capacity(self.head.data); - let new_min_chunk_size = uint::max(n_bytes, chunk_size); + let new_min_chunk_size = num::max(n_bytes, chunk_size); self.chunks = @mut MutCons(copy self.head, self.chunks); self.head = chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false); diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 72b6e6dc6500a..dc65ef36b67e6 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -12,6 +12,7 @@ use std::cmp; +use std::num; use std::ops; use std::uint; use std::vec; @@ -726,7 +727,7 @@ impl Set for BitvSet { } let nbits = self.capacity(); if value >= nbits { - let newsize = uint::max(value, nbits * 2) / uint::bits + 1; + let newsize = num::max(value, nbits * 2) / uint::bits + 1; assert!(newsize > self.bitv.storage.len()); self.bitv.storage.grow(newsize, &0); } @@ -825,7 +826,7 @@ impl BitvSet { /// and w1/w2 are the words coming from the two vectors self, other. fn each_common(&self, other: &BitvSet, f: &fn(uint, uint, uint) -> bool) -> bool { - let min = uint::min(self.bitv.storage.len(), + let min = num::min(self.bitv.storage.len(), other.bitv.storage.len()); self.bitv.storage.slice(0, min).iter().enumerate().advance(|(i, &w)| { f(i * uint::bits, w, other.bitv.storage[i]) @@ -843,7 +844,7 @@ impl BitvSet { f: &fn(bool, uint, uint) -> bool) -> bool { let len1 = self.bitv.storage.len(); let len2 = other.bitv.storage.len(); - let min = uint::min(len1, len2); + let min = num::min(len1, len2); /* only one of these loops will execute and that's the point */ for self.bitv.storage.slice(min, len1).iter().enumerate().advance |(i, &w)| { diff --git a/src/libextra/deque.rs b/src/libextra/deque.rs index 36ebf295aabaa..9ce5e2c7ba20a 100644 --- a/src/libextra/deque.rs +++ b/src/libextra/deque.rs @@ -10,6 +10,7 @@ //! A double-ended queue implemented as a circular buffer +use std::num; use std::uint; use std::vec; use std::iterator::FromIterator; @@ -51,7 +52,7 @@ impl Deque { /// Create an empty Deque with space for at least `n` elements. pub fn with_capacity(n: uint) -> Deque { Deque{nelts: 0, lo: 0, - elts: vec::from_fn(uint::max(MINIMUM_CAPACITY, n), |_| None)} + elts: vec::from_fn(num::max(MINIMUM_CAPACITY, n), |_| None)} } /// Return a reference to the first element in the deque diff --git a/src/libextra/net/tcp.rs b/src/libextra/net/tcp.rs index e0ed313bc0269..fd80d8e04653b 100644 --- a/src/libextra/net/tcp.rs +++ b/src/libextra/net/tcp.rs @@ -28,7 +28,7 @@ use std::comm::{stream, Port, SharedChan}; use std::ptr; use std::result::{Result}; use std::result; -use std::uint; +use std::num; use std::vec; pub mod rustrt { @@ -880,7 +880,7 @@ impl io::Reader for TcpSocketBuf { let needed = len - count; if nbuffered > 0 { unsafe { - let ncopy = uint::min(nbuffered, needed); + let ncopy = num::min(nbuffered, needed); let dst = ptr::mut_offset( vec::raw::to_mut_ptr(buf), count); let src = ptr::offset( diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index 5867b13f55656..13b55a4609b9c 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -21,6 +21,7 @@ A BigInt is a combination of BigUint and Sign. use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater}; use std::int; +use std::num; use std::num::{IntConvertible, Zero, One, ToStrRadix, FromStrRadix, Orderable}; use std::str; use std::uint; @@ -204,7 +205,7 @@ impl Unsigned for BigUint {} impl Add for BigUint { fn add(&self, other: &BigUint) -> BigUint { - let new_len = uint::max(self.data.len(), other.data.len()); + let new_len = num::max(self.data.len(), other.data.len()); let mut carry = 0; let mut sum = do vec::from_fn(new_len) |i| { @@ -224,7 +225,7 @@ impl Add for BigUint { impl Sub for BigUint { fn sub(&self, other: &BigUint) -> BigUint { - let new_len = uint::max(self.data.len(), other.data.len()); + let new_len = num::max(self.data.len(), other.data.len()); let mut borrow = 0; let diff = do vec::from_fn(new_len) |i| { @@ -260,7 +261,7 @@ impl Mul for BigUint { // = a1*b1 * base^2 + // (a1*b1 + a0*b0 - (a1-b0)*(b1-a0)) * base + // a0*b0 - let half_len = uint::max(s_len, o_len) / 2; + let half_len = num::max(s_len, o_len) / 2; let (sHi, sLo) = cut_at(self, half_len); let (oHi, oLo) = cut_at(other, half_len); @@ -297,7 +298,7 @@ impl Mul for BigUint { fn cut_at(a: &BigUint, n: uint) -> (BigUint, BigUint) { - let mid = uint::min(a.data.len(), n); + let mid = num::min(a.data.len(), n); return (BigUint::from_slice(a.data.slice(mid, a.data.len())), BigUint::from_slice(a.data.slice(0, mid))); } @@ -482,7 +483,7 @@ impl Integer for BigUint { impl IntConvertible for BigUint { fn to_int(&self) -> int { - uint::min(self.to_uint(), int::max_value as uint) as int + num::min(self.to_uint(), int::max_value as uint) as int } @@ -580,7 +581,7 @@ impl BigUint { let mut n: BigUint = Zero::zero(); let mut power: BigUint = One::one(); loop { - let start = uint::max(end, unit_len) - unit_len; + let start = num::max(end, unit_len) - unit_len; match uint::parse_bytes(buf.slice(start, end), radix) { // FIXME(#6102): Assignment operator for BigInt causes ICE // Some(d) => n += BigUint::from_uint(d) * power, @@ -1055,9 +1056,9 @@ impl IntConvertible for BigInt { fn to_int(&self) -> int { match self.sign { - Plus => uint::min(self.to_uint(), int::max_value as uint) as int, + Plus => num::min(self.to_uint(), int::max_value as uint) as int, Zero => 0, - Minus => uint::min((-self).to_uint(), + Minus => num::min((-self).to_uint(), (int::max_value as uint) + 1) as int } } diff --git a/src/libextra/par.rs b/src/libextra/par.rs index d737698cfe2ca..8023fe2c5da23 100644 --- a/src/libextra/par.rs +++ b/src/libextra/par.rs @@ -10,9 +10,9 @@ use std::cast; +use std::num; use std::ptr; use std::sys; -use std::uint; use std::vec; use future_spawn = future::spawn; @@ -44,7 +44,7 @@ fn map_slices( ~[f()(0u, xs)] } else { - let num_tasks = uint::min(MAX_TASKS, len / MIN_GRANULARITY); + let num_tasks = num::min(MAX_TASKS, len / MIN_GRANULARITY); let items_per_task = len / num_tasks; @@ -52,7 +52,7 @@ fn map_slices( let mut base = 0u; info!("spawning tasks"); while base < len { - let end = uint::min(len, base + items_per_task); + let end = num::min(len, base + items_per_task); do xs.as_imm_buf |p, _len| { let f = f(); let base = base; diff --git a/src/libextra/sort.rs b/src/libextra/sort.rs index f59a2414aaeb7..68a678869da13 100644 --- a/src/libextra/sort.rs +++ b/src/libextra/sort.rs @@ -840,7 +840,7 @@ mod test_qsort { let expected = ~[1, 2, 3]; - do quick_sort(names) |x, y| { int::le(*x, *y) }; + do quick_sort(names) |x, y| { *x < *y }; let immut_names = names; diff --git a/src/libextra/stats.rs b/src/libextra/stats.rs index 0271b393f6116..5446515c1efad 100644 --- a/src/libextra/stats.rs +++ b/src/libextra/stats.rs @@ -12,7 +12,6 @@ use sort; use std::cmp; use std::io; use std::num; -use std::f64; use std::vec; // NB: this can probably be rewritten in terms of num::Num @@ -178,7 +177,7 @@ impl<'self> Stats for &'self [f64] { } fn std_dev(self) -> f64 { - f64::sqrt(self.var()) + self.var().sqrt() } fn std_dev_pct(self) -> f64 { diff --git a/src/libextra/time.rs b/src/libextra/time.rs index a64b23743287e..d74656dcc2e4d 100644 --- a/src/libextra/time.rs +++ b/src/libextra/time.rs @@ -11,9 +11,9 @@ #[allow(missing_doc)]; -use std::i32; use std::int; use std::io; +use std::num; use std::str; static NSEC_PER_SEC: i32 = 1_000_000_000_i32; @@ -249,7 +249,7 @@ impl Tm { } else { let s = self.strftime("%Y-%m-%dT%H:%M:%S"); let sign = if self.tm_gmtoff > 0_i32 { '+' } else { '-' }; - let mut m = i32::abs(self.tm_gmtoff) / 60_i32; + let mut m = num::abs(self.tm_gmtoff) / 60_i32; let h = m / 60_i32; m -= h * 60_i32; s + fmt!("%c%02d:%02d", sign, h as int, m as int) @@ -832,7 +832,7 @@ priv fn do_strftime(format: &str, tm: &Tm) -> ~str { 'Z' => copy tm.tm_zone, 'z' => { let sign = if tm.tm_gmtoff > 0_i32 { '+' } else { '-' }; - let mut m = i32::abs(tm.tm_gmtoff) / 60_i32; + let mut m = num::abs(tm.tm_gmtoff) / 60_i32; let h = m / 60_i32; m -= h * 60_i32; fmt!("%c%02d%02d", sign, h as int, m as int) diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index f2dea8b9bbaf3..8fac055d26f68 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -13,7 +13,7 @@ //! `TotalOrd`. -use std::uint; +use std::num; use std::util::{swap, replace}; // This is implemented as an AA tree, which is a simplified variation of @@ -63,7 +63,7 @@ fn lt(a: &TreeMap, let mut y = b.iter(); let (a_len, b_len) = (a.len(), b.len()); - for uint::min(a_len, b_len).times { + for num::min(a_len, b_len).times { let (key_a, value_a) = x.next().unwrap(); let (key_b, value_b) = y.next().unwrap(); if *key_a < *key_b { return true; } diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index 19dbb941e5566..62c1f670cf9b5 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -14,6 +14,7 @@ use metadata::cstore; use metadata::filesearch; use std::hashmap::HashSet; +use std::num; use std::os; use std::uint; use std::util; @@ -141,7 +142,7 @@ pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path { assert!(len1 > 0); assert!(len2 > 0); - let max_common_path = uint::min(len1, len2) - 1; + let max_common_path = num::min(len1, len2) - 1; let mut start_idx = 0; while start_idx < max_common_path && split1[start_idx] == split2[start_idx] { diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 9aefb8fdb5579..98f7dd766a43f 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -25,11 +25,11 @@ use syntax::{ast, attr}; use std::cast; use std::io; +use std::num; use std::option; use std::os::consts::{macos, freebsd, linux, android, win32}; use std::ptr; use std::str; -use std::uint; use std::vec; use extra::flate; @@ -213,7 +213,7 @@ fn get_metadata_section(os: os, let vlen = encoder::metadata_encoding_version.len(); debug!("checking %u bytes of metadata-version stamp", vlen); - let minsz = uint::min(vlen, csz); + let minsz = num::min(vlen, csz); let mut version_ok = false; do 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 02f7294ffcd3b..3d6f8a3615f82 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -18,6 +18,7 @@ use middle::typeck::method_map; use middle::moves; use util::ppaux::ty_to_str; +use std::num; use std::uint; use std::vec; use extra::sort; @@ -234,7 +235,7 @@ pub fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@pat]) -> useful { let max_len = do m.rev_iter().fold(0) |max_len, r| { match r[0].node { pat_vec(ref before, _, ref after) => { - uint::max(before.len() + after.len(), max_len) + num::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 7eac2df10b6c7..1492f44d97745 100644 --- a/src/librustc/middle/trans/cabi_arm.rs +++ b/src/librustc/middle/trans/cabi_arm.rs @@ -14,8 +14,8 @@ use middle::trans::cabi::{ABIInfo, FnType, LLVMType}; use middle::trans::type_::Type; +use std::num; use std::option::{Option, None, Some}; -use std::uint; fn align_up_to(off: uint, a: uint) -> uint { return (off + a - 1u) / a * a; @@ -41,7 +41,7 @@ fn ty_align(ty: Type) -> uint { 1 } else { let str_tys = ty.field_types(); - str_tys.iter().fold(1, |a, t| uint::max(a, ty_align(*t))) + str_tys.iter().fold(1, |a, t| num::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 c95ae994cebea..a9407092eed45 100644 --- a/src/librustc/middle/trans/cabi_mips.rs +++ b/src/librustc/middle/trans/cabi_mips.rs @@ -10,7 +10,7 @@ use std::libc::c_uint; -use std::uint; +use std::num; use std::vec; use lib::llvm::{llvm, Integer, Pointer, Float, Double, Struct, Array}; use lib::llvm::{Attribute, StructRetAttribute}; @@ -43,7 +43,7 @@ fn ty_align(ty: Type) -> uint { 1 } else { let str_tys = ty.field_types(); - str_tys.iter().fold(1, |a, t| uint::max(a, ty_align(*t))) + str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t))) } } Array => { @@ -97,7 +97,7 @@ fn classify_arg_ty(ty: Type, offset: &mut uint) -> (LLVMType, Option) let size = ty_size(ty) * 8; let mut align = ty_align(ty); - align = uint::min(uint::max(align, 4), 8); + align = num::min(num::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 8fa86ea77aba9..6a0387d14ea43 100644 --- a/src/librustc/middle/trans/cabi_x86_64.rs +++ b/src/librustc/middle/trans/cabi_x86_64.rs @@ -18,6 +18,7 @@ use middle::trans::cabi::*; use middle::trans::type_::Type; +use std::num; use std::option; use std::option::Option; use std::uint; @@ -104,7 +105,7 @@ fn classify_ty(ty: Type) -> ~[RegClass] { 1 } else { let str_tys = ty.field_types(); - str_tys.iter().fold(1, |a, t| uint::max(a, ty_align(*t))) + str_tys.iter().fold(1, |a, t| num::max(a, ty_align(*t))) } } Array => { diff --git a/src/librustc/rustc.rs b/src/librustc/rustc.rs index 60fc485c4db5d..f4014180c64bf 100644 --- a/src/librustc/rustc.rs +++ b/src/librustc/rustc.rs @@ -34,11 +34,11 @@ use driver::session; use middle::lint; use std::io; +use std::num; use std::os; use std::result; use std::str; use std::task; -use std::uint; use std::vec; use extra::getopts::{groups, opt_present}; use extra::getopts; @@ -153,7 +153,7 @@ Available lint options: let lint_dict = lint::get_lint_dict(); let mut max_key = 0; - for lint_dict.each_key |k| { max_key = uint::max(k.len(), max_key); } + for lint_dict.each_key |k| { max_key = num::max(k.len(), max_key); } fn padded(max: uint, s: &str) -> ~str { str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s } diff --git a/src/librustdoc/unindent_pass.rs b/src/librustdoc/unindent_pass.rs index 7df6b32078027..4c2464f8b3473 100644 --- a/src/librustdoc/unindent_pass.rs +++ b/src/librustdoc/unindent_pass.rs @@ -20,6 +20,7 @@ middle of a line, and each of the following lines is indented. */ +use std::num; use std::uint; use pass::Pass; use text_pass; @@ -69,7 +70,7 @@ fn unindent(s: &str) -> ~str { false } }; - uint::min(min_indent, spaces) + num::min(min_indent, spaces) } }; diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 2d80dc2be152d..6c93cd0dc8682 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -19,6 +19,7 @@ use container::{Container, Mutable, Map, Set}; use cmp::{Eq, Equiv}; use hash::Hash; use iterator::{Iterator, IteratorUtil}; +use num; use option::{None, Option, Some}; use rand::RngUtil; use rand; @@ -74,7 +75,7 @@ pub fn linear_map_with_capacity( fn linear_map_with_capacity_and_keys( k0: u64, k1: u64, initial_capacity: uint) -> HashMap { - let cap = uint::max(INITIAL_CAPACITY, initial_capacity); + let cap = num::max(INITIAL_CAPACITY, initial_capacity); HashMap { k0: k0, k1: k1, resize_at: resize_at(cap), diff --git a/src/libstd/io.rs b/src/libstd/io.rs index 38826dd411b68..347fa98885686 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -53,6 +53,7 @@ use int; use libc; use libc::{c_int, c_long, c_void, size_t, ssize_t}; use libc::consts::os::posix88::*; +use num; use os; use cast; use path::Path; @@ -1054,7 +1055,7 @@ pub struct BytesReader { impl Reader for BytesReader { fn read(&self, bytes: &mut [u8], len: uint) -> uint { - let count = uint::min(len, self.bytes.len() - *self.pos); + let count = num::min(len, self.bytes.len() - *self.pos); let view = self.bytes.slice(*self.pos, self.bytes.len()); vec::bytes::copy_memory(bytes, view, count); @@ -1660,7 +1661,7 @@ impl Writer for BytesWriter { let v_len = v.len(); let bytes = &mut *self.bytes; - let count = uint::max(bytes.len(), *self.pos + v_len); + let count = num::max(bytes.len(), *self.pos + v_len); bytes.reserve(count); unsafe { diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index a84c27cd91882..faf9b2e2390dc 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -21,9 +21,7 @@ use to_str; pub use cmath::c_float_targ_consts::*; -// An inner module is required to get the #[inline] attribute on the -// functions. -pub use self::delegated::*; +use self::delegated::*; macro_rules! delegate( ( @@ -35,6 +33,8 @@ macro_rules! delegate( ) -> $rv:ty = $bound_name:path ),* ) => ( + // An inner module is required to get the #[inline] attribute on the + // functions. mod delegated { use cmath::c_float_utils; use libc::{c_float, c_int}; @@ -116,50 +116,6 @@ pub static infinity: f32 = 1.0_f32/0.0_f32; pub static neg_infinity: f32 = -1.0_f32/0.0_f32; -#[inline] -pub fn add(x: f32, y: f32) -> f32 { return x + y; } - -#[inline] -pub fn sub(x: f32, y: f32) -> f32 { return x - y; } - -#[inline] -pub fn mul(x: f32, y: f32) -> f32 { return x * y; } - -#[inline] -pub fn div(x: f32, y: f32) -> f32 { return x / y; } - -#[inline] -pub fn rem(x: f32, y: f32) -> f32 { return x % y; } - -#[inline] -pub fn lt(x: f32, y: f32) -> bool { return x < y; } - -#[inline] -pub fn le(x: f32, y: f32) -> bool { return x <= y; } - -#[inline] -pub fn eq(x: f32, y: f32) -> bool { return x == y; } - -#[inline] -pub fn ne(x: f32, y: f32) -> bool { return x != y; } - -#[inline] -pub fn ge(x: f32, y: f32) -> bool { return x >= y; } - -#[inline] -pub fn gt(x: f32, y: f32) -> bool { return x > y; } - -#[inline] -pub fn fmax(x: f32, y: f32) -> f32 { - if x >= y || y.is_NaN() { x } else { y } -} - -#[inline] -pub fn fmin(x: f32, y: f32) -> f32 { - if x <= y || y.is_NaN() { x } else { y } -} - - // FIXME (#1999): replace the predicates below with llvm intrinsics or // calls to the libmath macros in the rust runtime for performance. @@ -251,13 +207,23 @@ impl Orderable for f32 { /// Returns `NaN` if either of the numbers are `NaN`. #[inline] fn min(&self, other: &f32) -> f32 { - if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmin(*self, *other) } + cond!( + (self.is_NaN()) { *self } + (other.is_NaN()) { *other } + (*self < *other) { *self } + _ { *other } + ) } /// Returns `NaN` if either of the numbers are `NaN`. #[inline] fn max(&self, other: &f32) -> f32 { - if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) } + cond!( + (self.is_NaN()) { *self } + (other.is_NaN()) { *other } + (*self > *other) { *self } + _ { *other } + ) } /// Returns the number constrained within the range `mn <= self <= mx`. diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index 216963e04143d..c7db60e6fd264 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -23,9 +23,7 @@ use to_str; pub use cmath::c_double_targ_consts::*; pub use cmp::{min, max}; -// An inner module is required to get the #[inline] attribute on the -// functions. -pub use self::delegated::*; +use self::delegated::*; macro_rules! delegate( ( @@ -37,6 +35,8 @@ macro_rules! delegate( ) -> $rv:ty = $bound_name:path ),* ) => ( + // An inner module is required to get the #[inline] attribute on the + // functions. mod delegated { use cmath::c_double_utils; use libc::{c_double, c_int}; @@ -142,49 +142,6 @@ pub static infinity: f64 = 1.0_f64/0.0_f64; pub static neg_infinity: f64 = -1.0_f64/0.0_f64; -#[inline] -pub fn add(x: f64, y: f64) -> f64 { return x + y; } - -#[inline] -pub fn sub(x: f64, y: f64) -> f64 { return x - y; } - -#[inline] -pub fn mul(x: f64, y: f64) -> f64 { return x * y; } - -#[inline] -pub fn div(x: f64, y: f64) -> f64 { return x / y; } - -#[inline] -pub fn rem(x: f64, y: f64) -> f64 { return x % y; } - -#[inline] -pub fn lt(x: f64, y: f64) -> bool { return x < y; } - -#[inline] -pub fn le(x: f64, y: f64) -> bool { return x <= y; } - -#[inline] -pub fn eq(x: f64, y: f64) -> bool { return x == y; } - -#[inline] -pub fn ne(x: f64, y: f64) -> bool { return x != y; } - -#[inline] -pub fn ge(x: f64, y: f64) -> bool { return x >= y; } - -#[inline] -pub fn gt(x: f64, y: f64) -> bool { return x > y; } - -#[inline] -pub fn fmax(x: f64, y: f64) -> f64 { - if x >= y || y.is_NaN() { x } else { y } -} - -#[inline] -pub fn fmin(x: f64, y: f64) -> f64 { - if x <= y || y.is_NaN() { x } else { y } -} - // FIXME (#1999): add is_normal, is_subnormal, and fpclassify /* Module: consts */ @@ -273,13 +230,23 @@ impl Orderable for f64 { /// Returns `NaN` if either of the numbers are `NaN`. #[inline] fn min(&self, other: &f64) -> f64 { - if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmin(*self, *other) } + cond!( + (self.is_NaN()) { *self } + (other.is_NaN()) { *other } + (*self < *other) { *self } + _ { *other } + ) } /// Returns `NaN` if either of the numbers are `NaN`. #[inline] fn max(&self, other: &f64) -> f64 { - if self.is_NaN() || other.is_NaN() { Float::NaN() } else { fmax(*self, *other) } + cond!( + (self.is_NaN()) { *self } + (other.is_NaN()) { *other } + (*self > *other) { *self } + _ { *other } + ) } /// Returns the number constrained within the range `mn <= self <= mx`. diff --git a/src/libstd/num/float.rs b/src/libstd/num/float.rs index d73ff16c6f7bc..486d35620899a 100644 --- a/src/libstd/num/float.rs +++ b/src/libstd/num/float.rs @@ -23,22 +23,12 @@ #[allow(missing_doc)]; #[allow(non_uppercase_statics)]; -use f64; -use libc::c_int; use num::{Zero, One, strconv}; use num::FPCategory; use num; use prelude::*; use to_str; -pub use f64::{add, sub, mul, div, rem, lt, le, eq, ne, ge, gt}; -pub use f64::{acos, asin, atan2, cbrt, ceil, copysign, cosh, floor}; -pub use f64::{erf, erfc, exp, exp_m1, exp2, abs_sub}; -pub use f64::{mul_add, fmax, fmin, next_after, frexp, hypot, ldexp}; -pub use f64::{lgamma, ln, log_radix, ln_1p, log10, log2, ilog_radix}; -pub use f64::{modf, pow, powi, round, sinh, tanh, tgamma, trunc}; -pub use f64::{j0, j1, jn, y0, y1, yn}; - pub static NaN: float = 0.0/0.0; pub static infinity: float = 1.0/0.0; @@ -342,31 +332,6 @@ pub fn pow_with_uint(base: uint, pow: uint) -> float { return total; } -#[inline] -pub fn abs(x: float) -> float { - f64::abs(x as f64) as float -} -#[inline] -pub fn sqrt(x: float) -> float { - f64::sqrt(x as f64) as float -} -#[inline] -pub fn atan(x: float) -> float { - f64::atan(x as f64) as float -} -#[inline] -pub fn sin(x: float) -> float { - f64::sin(x as f64) as float -} -#[inline] -pub fn cos(x: float) -> float { - f64::cos(x as f64) as float -} -#[inline] -pub fn tan(x: float) -> float { - f64::tan(x as f64) as float -} - impl Num for float {} #[cfg(not(test))] @@ -443,19 +408,19 @@ impl One for float { impl Round for float { /// Round half-way cases toward `neg_infinity` #[inline] - fn floor(&self) -> float { floor(*self as f64) as float } + fn floor(&self) -> float { (*self as f64).floor() as float } /// Round half-way cases toward `infinity` #[inline] - fn ceil(&self) -> float { ceil(*self as f64) as float } + fn ceil(&self) -> float { (*self as f64).ceil() as float } /// Round half-way cases away from `0.0` #[inline] - fn round(&self) -> float { round(*self as f64) as float } + fn round(&self) -> float { (*self as f64).round() as float } /// The integer part of the number (rounds towards `0.0`) #[inline] - fn trunc(&self) -> float { trunc(*self as f64) as float } + fn trunc(&self) -> float { (*self as f64).trunc() as float } /// /// The fractional part of the number, satisfying: @@ -727,31 +692,30 @@ impl Real for float { impl RealExt for float { #[inline] fn lgamma(&self) -> (int, float) { - let mut sign = 0; - let result = lgamma(*self as f64, &mut sign); - (sign as int, result as float) + let (sign, value) = (*self as f64).lgamma(); + (sign, value as float) } #[inline] - fn tgamma(&self) -> float { tgamma(*self as f64) as float } + fn tgamma(&self) -> float { (*self as f64).tgamma() as float } #[inline] - fn j0(&self) -> float { j0(*self as f64) as float } + fn j0(&self) -> float { (*self as f64).j0() as float } #[inline] - fn j1(&self) -> float { j1(*self as f64) as float } + fn j1(&self) -> float { (*self as f64).j1() as float } #[inline] - fn jn(&self, n: int) -> float { jn(n as c_int, *self as f64) as float } + fn jn(&self, n: int) -> float { (*self as f64).jn(n) as float } #[inline] - fn y0(&self) -> float { y0(*self as f64) as float } + fn y0(&self) -> float { (*self as f64).y0() as float } #[inline] - fn y1(&self) -> float { y1(*self as f64) as float } + fn y1(&self) -> float { (*self as f64).y1() as float } #[inline] - fn yn(&self, n: int) -> float { yn(n as c_int, *self as f64) as float } + fn yn(&self, n: int) -> float { (*self as f64).yn(n) as float } } #[cfg(not(test))] @@ -792,7 +756,7 @@ impl Neg for float { impl Signed for float { /// Computes the absolute value. Returns `NaN` if the number is `NaN`. #[inline] - fn abs(&self) -> float { abs(*self) } + fn abs(&self) -> float { (*self as f64).abs() as float } /// /// The positive difference of two numbers. Returns `0.0` if the number is less than or @@ -812,7 +776,7 @@ impl Signed for float { /// #[inline] fn signum(&self) -> float { - if self.is_NaN() { NaN } else { f64::copysign(1.0, *self as f64) as float } + (*self as f64).signum() as float } /// Returns `true` if the number is positive, including `+0.0` and `infinity` @@ -939,13 +903,13 @@ impl Float for float { /// #[inline] fn mul_add(&self, a: float, b: float) -> float { - mul_add(*self as f64, a as f64, b as f64) as float + (*self as f64).mul_add(a as f64, b as f64) as float } /// Returns the next representable floating-point value in the direction of `other` #[inline] fn next_after(&self, other: float) -> float { - next_after(*self as f64, other as f64) as float + (*self as f64).next_after(other as f64) as float } } diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index c2eebf9a3e41a..75e0bbcb71b04 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -29,62 +29,6 @@ pub static bytes : uint = ($bits / 8); pub static min_value: $T = (-1 as $T) << (bits - 1); pub static max_value: $T = min_value - 1 as $T; -/// Calculates the sum of two numbers -#[inline] -pub fn add(x: $T, y: $T) -> $T { x + y } -/// Subtracts the second number from the first -#[inline] -pub fn sub(x: $T, y: $T) -> $T { x - y } -/// Multiplies two numbers together -#[inline] -pub fn mul(x: $T, y: $T) -> $T { x * y } -/// Divides the first argument by the second argument (using integer division) -/// Divides the first argument by the second argument (using integer division) -#[inline] -pub fn div(x: $T, y: $T) -> $T { x / y } - -/// -/// Returns the remainder of y / x. -/// -/// # Examples -/// ~~~ -/// assert!(int::rem(5 / 2) == 1); -/// ~~~ -/// -/// When faced with negative numbers, the result copies the sign of the -/// dividend. -/// -/// ~~~ -/// assert!(int::rem(2 / -3) == 2); -/// ~~~ -/// -/// ~~~ -/// assert!(int::rem(-2 / 3) == -2); -/// ~~~ -/// -/// -#[inline] -pub fn rem(x: $T, y: $T) -> $T { x % y } - -/// Returns true iff `x < y` -#[inline] -pub fn lt(x: $T, y: $T) -> bool { x < y } -/// Returns true iff `x <= y` -#[inline] -pub fn le(x: $T, y: $T) -> bool { x <= y } -/// Returns true iff `x == y` -#[inline] -pub fn eq(x: $T, y: $T) -> bool { x == y } -/// Returns true iff `x != y` -#[inline] -pub fn ne(x: $T, y: $T) -> bool { x != y } -/// Returns true iff `x >= y` -#[inline] -pub fn ge(x: $T, y: $T) -> bool { x >= y } -/// Returns true iff `x > y` -#[inline] -pub fn gt(x: $T, y: $T) -> bool { x > y } - /// /// Iterate over the range [`lo`..`hi`) /// @@ -137,16 +81,6 @@ pub fn range_rev(hi: $T, lo: $T, it: &fn($T) -> bool) -> bool { range_step(hi, lo, -1 as $T, it) } -/// Computes the bitwise complement -#[inline] -pub fn compl(i: $T) -> $T { - -1 as $T ^ i -} - -/// Computes the absolute value -#[inline] -pub fn abs(i: $T) -> $T { i.abs() } - impl Num for $T {} #[cfg(not(test))] diff --git a/src/libstd/num/num.rs b/src/libstd/num/num.rs index b856c3c65ea5a..4468b51c26148 100644 --- a/src/libstd/num/num.rs +++ b/src/libstd/num/num.rs @@ -46,6 +46,9 @@ pub trait Orderable: Ord { fn clamp(&self, mn: &Self, mx: &Self) -> Self; } +#[inline(always)] pub fn min(a: T, b: T) -> T { a.min(&b) } +#[inline(always)] pub fn max(a: T, b: T) -> T { a.max(&b) } + pub trait Zero { fn zero() -> Self; // FIXME (#5527): This should be an associated constant fn is_zero(&self) -> bool; @@ -65,12 +68,10 @@ pub trait Signed: Num fn is_negative(&self) -> bool; } -pub trait Unsigned: Num {} +#[inline(always)] pub fn abs(value: T) -> T { value.abs() } +#[inline(always)] pub fn signum(value: T) -> T { value.signum() } -// This should be moved into the default implementation for Signed::abs -pub fn abs>(v: T) -> T { - if v < Zero::zero() { v.neg() } else { v } -} +pub trait Unsigned: Num {} pub trait Integer: Num + Orderable @@ -113,6 +114,8 @@ pub trait Algebraic { fn hypot(&self, other: &Self) -> Self; } +#[inline(always)] pub fn sqrt(value: T) -> T { value.sqrt() } + pub trait Trigonometric { fn sin(&self) -> Self; fn cos(&self) -> Self; @@ -124,6 +127,16 @@ pub trait Trigonometric { fn sin_cos(&self) -> (Self, Self); } +#[inline(always)] pub fn sin(value: T) -> T { value.sin() } +#[inline(always)] pub fn cos(value: T) -> T { value.cos() } +#[inline(always)] pub fn tan(value: T) -> T { value.tan() } + +#[inline(always)] pub fn asin(value: T) -> T { value.asin() } +#[inline(always)] pub fn acos(value: T) -> T { value.acos() } +#[inline(always)] pub fn atan(value: T) -> T { value.atan() } + +#[inline(always)] pub fn atan2(x: T, y: T) -> T { x.atan2(&y) } + pub trait Exponential { fn exp(&self) -> Self; fn exp2(&self) -> Self; @@ -133,6 +146,14 @@ pub trait Exponential { fn log10(&self) -> Self; } +#[inline(always)] pub fn exp(value: T) -> T { value.exp() } +#[inline(always)] pub fn exp2(value: T) -> T { value.exp2() } + +#[inline(always)] pub fn ln(value: T) -> T { value.ln() } +#[inline(always)] pub fn log(value: T, base: T) -> T { value.log(&base) } +#[inline(always)] pub fn log2(value: T) -> T { value.log2() } +#[inline(always)] pub fn log10(value: T) -> T { value.log10() } + pub trait Hyperbolic: Exponential { fn sinh(&self) -> Self; fn cosh(&self) -> Self; @@ -142,6 +163,14 @@ pub trait Hyperbolic: Exponential { fn atanh(&self) -> Self; } +#[inline(always)] pub fn sinh(value: T) -> T { value.sinh() } +#[inline(always)] pub fn cosh(value: T) -> T { value.cosh() } +#[inline(always)] pub fn tanh(value: T) -> T { value.tanh() } + +#[inline(always)] pub fn asinh(value: T) -> T { value.asinh() } +#[inline(always)] pub fn acosh(value: T) -> T { value.acosh() } +#[inline(always)] pub fn atanh(value: T) -> T { value.atanh() } + /// /// Defines constants and methods common to real numbers /// diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index d185b2a05a8c4..de1b997b14b52 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -30,42 +30,6 @@ pub static bytes : uint = ($bits / 8); pub static min_value: $T = 0 as $T; pub static max_value: $T = 0 as $T - 1 as $T; -/// Calculates the sum of two numbers -#[inline] -pub fn add(x: $T, y: $T) -> $T { x + y } -/// Subtracts the second number from the first -#[inline] -pub fn sub(x: $T, y: $T) -> $T { x - y } -/// Multiplies two numbers together -#[inline] -pub fn mul(x: $T, y: $T) -> $T { x * y } -/// Divides the first argument by the second argument (using integer division) -#[inline] -pub fn div(x: $T, y: $T) -> $T { x / y } -/// Calculates the integer remainder when x is divided by y (equivalent to the -/// '%' operator) -#[inline] -pub fn rem(x: $T, y: $T) -> $T { x % y } - -/// Returns true iff `x < y` -#[inline] -pub fn lt(x: $T, y: $T) -> bool { x < y } -/// Returns true iff `x <= y` -#[inline] -pub fn le(x: $T, y: $T) -> bool { x <= y } -/// Returns true iff `x == y` -#[inline] -pub fn eq(x: $T, y: $T) -> bool { x == y } -/// Returns true iff `x != y` -#[inline] -pub fn ne(x: $T, y: $T) -> bool { x != y } -/// Returns true iff `x >= y` -#[inline] -pub fn ge(x: $T, y: $T) -> bool { x >= y } -/// Returns true iff `x > y` -#[inline] -pub fn gt(x: $T, y: $T) -> bool { x > y } - #[inline] /** * Iterate through a range with a given step value. @@ -114,12 +78,6 @@ pub fn range_rev(hi: $T, lo: $T, it: &fn($T) -> bool) -> bool { range_step(hi, lo, -1 as $T_SIGNED, it) } -/// Computes the bitwise complement -#[inline] -pub fn compl(i: $T) -> $T { - max_value ^ i -} - impl Num for $T {} #[cfg(not(test))] diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs index 5054763d742b0..02c8694bf76e2 100644 --- a/src/libstd/rand.rs +++ b/src/libstd/rand.rs @@ -46,6 +46,7 @@ use container::Container; use int; use iterator::IteratorUtil; use local_data; +use num; use prelude::*; use str; use sys; @@ -463,7 +464,7 @@ impl RngUtil for R { */ fn gen_int_range(&mut self, start: int, end: int) -> int { assert!(start < end); - start + int::abs(self.gen::() % (end - start)) + start + num::abs(self.gen::() % (end - start)) } /** diff --git a/src/libstd/rand/distributions.rs b/src/libstd/rand/distributions.rs index e8dad2fc5e862..4d983b9495446 100644 --- a/src/libstd/rand/distributions.rs +++ b/src/libstd/rand/distributions.rs @@ -20,7 +20,7 @@ // Generating Random Variables"], but more robust. If one wanted, one // could implement VIZIGNOR the ZIGNOR paper for more speed. -use f64; +use num; use rand::{Rng,Rand}; mod ziggurat_tables; @@ -39,7 +39,7 @@ fn ziggurat(rng: &mut R, let i: uint = rng.gen::() & 0xff; let x = u * X[i]; - let test_x = if center_u {f64::abs(x)} else {x}; + let test_x = if center_u {num::abs(x)} else {x}; // algebraically equivalent to |u| < X[i+1]/X[i] (or u < X[i+1]/X[i]) if test_x < X[i + 1] { @@ -79,7 +79,7 @@ impl Rand for StandardNormal { fn rand(rng: &mut R) -> StandardNormal { #[inline] fn pdf(x: f64) -> f64 { - f64::exp((-x*x/2.0) as f64) as f64 + ((-x*x/2.0) as f64).exp() } #[inline] fn zero_case(rng: &mut R, u: f64) -> f64 { @@ -89,15 +89,16 @@ impl Rand for StandardNormal { // do-while, so the condition should be true on the first // run, they get overwritten anyway (0 < 1, so these are // good). - let mut x = 1.0; - let mut y = 0.0; + let mut x = 1.0f64; + let mut y = 0.0f64; // XXX infinities? - while -2.0*y < x * x { - x = f64::ln(rng.gen()) / ziggurat_tables::ZIG_NORM_R; - y = f64::ln(rng.gen()); + while -2.0 * y < x * x { + x = rng.gen::().ln() / ziggurat_tables::ZIG_NORM_R; + y = rng.gen::().ln(); } - if u < 0.0 {x-ziggurat_tables::ZIG_NORM_R} else {ziggurat_tables::ZIG_NORM_R-x} + + if u < 0.0 { x - ziggurat_tables::ZIG_NORM_R } else { ziggurat_tables::ZIG_NORM_R - x } } StandardNormal(ziggurat( @@ -128,17 +129,17 @@ impl Rand for StandardNormal { /// ~~~ pub struct Exp1(f64); -// This could be done via `-f64::ln(rng.gen::())` but that is slower. +// This could be done via `-rng.gen::().ln()` but that is slower. impl Rand for Exp1 { #[inline] fn rand(rng: &mut R) -> Exp1 { #[inline] fn pdf(x: f64) -> f64 { - f64::exp(-x) + (-x).exp() } #[inline] fn zero_case(rng: &mut R, _u: f64) -> f64 { - ziggurat_tables::ZIG_EXP_R - f64::ln(rng.gen()) + ziggurat_tables::ZIG_EXP_R - rng.gen::().ln() } Exp1(ziggurat(rng, false, diff --git a/src/libstd/unstable/extfmt.rs b/src/libstd/unstable/extfmt.rs index b1df5175c9206..64ac76756d53b 100644 --- a/src/libstd/unstable/extfmt.rs +++ b/src/libstd/unstable/extfmt.rs @@ -477,7 +477,7 @@ pub mod rt { use float; use str; use sys; - use int; + use num; use uint; use vec; use option::{Some, None, Option}; @@ -503,7 +503,7 @@ pub mod rt { pub fn conv_int(cv: Conv, i: int, buf: &mut ~str) { let radix = 10; let prec = get_int_precision(cv); - let s : ~str = uint_to_str_prec(int::abs(i) as uint, radix, prec); + let s : ~str = uint_to_str_prec(num::abs(i) as uint, radix, prec); let head = if i >= 0 { if have_flag(cv.flags, flag_sign_always) { diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 191c2a4a0b2d3..309973def80f3 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1964,7 +1964,7 @@ pub mod raw { /// Operations on `[u8]` pub mod bytes { use libc; - use uint; + use num; use vec::raw; use vec; use ptr; @@ -1988,7 +1988,7 @@ pub mod bytes { pub fn memcmp(a: &~[u8], b: &~[u8]) -> int { let a_len = a.len(); let b_len = b.len(); - let n = uint::min(a_len, b_len) as libc::size_t; + let n = num::min(a_len, b_len) as libc::size_t; let r = unsafe { libc::memcmp(raw::to_ptr(*a) as *libc::c_void, raw::to_ptr(*b) as *libc::c_void, n) as int diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 565f181ab8598..78be8e6f180af 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -18,6 +18,7 @@ use visit; use std::hashmap::HashMap; use std::int; +use std::num; use std::option; use std::cast; use std::local_data; @@ -376,8 +377,8 @@ impl id_range { } pub fn add(&mut self, id: node_id) { - self.min = int::min(self.min, id); - self.max = int::max(self.max, id + 1); + self.min = num::min(self.min, id); + self.max = num::max(self.max, id + 1); } } diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 47de9334be15c..dbb8da1ebd736 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -22,7 +22,7 @@ use extra::time; use extra::deque::Deque; use extra::par; use std::hashmap::HashSet; -use std::int::abs; +use std::num::abs; use std::io; use std::os; use std::rand::RngUtil; diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index b65a6429f2c6c..a8742b3073f61 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -1,6 +1,5 @@ // Perlin noise benchmark from https://gist.github.com/1170424 -use std::f32; use std::float; use std::int; use std::rand::{Rng, RngUtil}; @@ -20,8 +19,8 @@ fn smooth(v: f32) -> f32 { v * v * (3.0 - 2.0 * v) } fn random_gradient(r: &mut R) -> Vec2 { let v = 2.0 * float::consts::pi * r.gen(); Vec2 { - x: float::cos(v) as f32, - y: float::sin(v) as f32, + x: v.cos() as f32, + y: v.sin() as f32, } } @@ -66,8 +65,8 @@ impl Noise2DContext { origins: &mut [Vec2, ..4], x: f32, y: f32) { - let x0f = f32::floor(x); - let y0f = f32::floor(y); + let x0f = x.floor(); + let y0f = y.floor(); let x0 = x0f as int; let y0 = y0f as int; let x1 = x0 + 1; diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index 7940b5a13c1bf..a56d1f44fa246 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -1,4 +1,3 @@ -use std::f64; use std::from_str::FromStr; use std::os; use std::uint::range; @@ -90,7 +89,7 @@ fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: i32) { d[2] = bodies[i].x[2] - bodies[j].x[2]; let d2 = d[0]*d[0] + d[1]*d[1] + d[2]*d[2]; - let mag = dt / (d2 * f64::sqrt(d2)); + let mag = dt / (d2 * d2.sqrt()); let a_mass = bodies[i].mass; let b_mass = bodies[j].mass; @@ -124,7 +123,7 @@ fn energy(bodies: &[Planet, ..N_BODIES]) -> f64 { for range(0, 3) |k| { d[k] = bodies[i].x[k] - bodies[j].x[k]; } - let dist = f64::sqrt(d[0]*d[0] + d[1]*d[1] + d[2]*d[2]); + let dist = (d[0]*d[0] + d[1]*d[1] + d[2]*d[2]).sqrt(); e -= bodies[i].mass * bodies[j].mass / dist; } } diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index 35a37e5533207..3e3df53eaad97 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::f64; use std::from_str::FromStr; use std::os; use std::vec; @@ -62,5 +61,5 @@ fn main() { mult_AtAv(v, u, tmp); } - println(fmt!("%.9f", f64::sqrt(dot(u,v) / dot(v,v)) as float)); + println(fmt!("%.9f", (dot(u,v) / dot(v,v)).sqrt() as float)); } diff --git a/src/test/run-pass/class-impl-parameterized-trait.rs b/src/test/run-pass/class-impl-parameterized-trait.rs index 655a9d4a0c072..31a300689785f 100644 --- a/src/test/run-pass/class-impl-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-parameterized-trait.rs @@ -58,7 +58,7 @@ class cat : map { fn find(&&k:int) -> Option { Some(self.get(k)) } fn remove(&&k:int) -> Option { self.meows -= k; Some(true) } fn each(f: &fn(&&int, &&bool) -> bool) { - let mut n = int::abs(self.meows); + let mut n = num::abs(self.meows); while n > 0 { if !f(n, true) { break; } n -= 1; diff --git a/src/test/run-pass/core-export-f64-sqrt.rs b/src/test/run-pass/core-export-f64-sqrt.rs deleted file mode 100644 index 3a683bc7cb92c..0000000000000 --- a/src/test/run-pass/core-export-f64-sqrt.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Regression test that f64 exports things properly - -use std::f64; -use std::float; - -pub fn main() { - - let digits: uint = 10 as uint; - - println(float::to_str_digits(f64::sqrt(42.0f64) as float, digits)); -} diff --git a/src/test/run-pass/trait-inheritance-self-in-supertype.rs b/src/test/run-pass/trait-inheritance-self-in-supertype.rs index f28f8cadfd98c..474e0cfe1db29 100644 --- a/src/test/run-pass/trait-inheritance-self-in-supertype.rs +++ b/src/test/run-pass/trait-inheritance-self-in-supertype.rs @@ -1,7 +1,6 @@ // Test for issue #4183: use of Self in supertraits. -use std::f32; -use std::f64; +use std::num; pub static FUZZY_EPSILON: float = 0.1; @@ -20,7 +19,7 @@ impl FuzzyEq for f32 { } fn fuzzy_eq_eps(&self, other: &f32, epsilon: &f32) -> bool { - f32::abs(*self - *other) < *epsilon + num::abs(*self - *other) < *epsilon } } @@ -34,7 +33,7 @@ impl FuzzyEq for f64 { } fn fuzzy_eq_eps(&self, other: &f64, epsilon: &f64) -> bool { - f64::abs(*self - *other) < *epsilon + num::abs(*self - *other) < *epsilon } } diff --git a/src/test/run-pass/utf8_idents.rs b/src/test/run-pass/utf8_idents.rs index 2e1bec53cee6c..3bc29ea13e343 100644 --- a/src/test/run-pass/utf8_idents.rs +++ b/src/test/run-pass/utf8_idents.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::float; +use std::num; pub fn main() { let ε = 0.00001; let Π = 3.14; let लंच = Π * Π + 1.54; - assert!(float::abs((लंच - 1.54) - (Π * Π)) < ε); + assert!(num::abs((लंच - 1.54) - (Π * Π)) < ε); assert_eq!(საჭმელად_გემრიელი_სადილი(), 0); }