about summary refs log tree commit diff
path: root/src/libextra
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-09 13:34:50 -0700
committerbors <bors@rust-lang.org>2013-07-09 13:34:50 -0700
commite388a80c234d628c4d1fab77dc3e3f2c04cbefc5 (patch)
tree694f659ded49c002e1aee01146eed625ab50c1bc /src/libextra
parent5aa0ca9b2eb28166d9ab2e86557a5b1f84230b46 (diff)
parent20a2fbd05557b21b7e3f38d17250388a350d3484 (diff)
auto merge of #7117 : jensnockert/rust/freestanding, r=cmr
The free-standing functions in f32, f64, i8, i16, i32, i64, u8, u16,
u32, u64, float, int, and uint are replaced with generic functions in
num instead.

This means that instead of having to know everywhere what the type is, like

~~~
f64::sin(x)
~~~

You can simply write code that uses the type-generic versions in num instead, this works for all types that implement the corresponding trait in num.

~~~
num::sin(x)
~~~

Note 1: If you were previously using any of those functions, just replace them
with the corresponding function with the same name in num.

Note 2: If you were using a function that corresponds to an operator, use the
operator instead.

Note 3: This is just https://github.com/mozilla/rust/pull/7090 reopened against master.
Diffstat (limited to 'src/libextra')
-rw-r--r--src/libextra/arena.rs5
-rw-r--r--src/libextra/bitv.rs7
-rw-r--r--src/libextra/deque.rs3
-rw-r--r--src/libextra/net/tcp.rs4
-rw-r--r--src/libextra/num/bigint.rs17
-rw-r--r--src/libextra/par.rs6
-rw-r--r--src/libextra/sort.rs2
-rw-r--r--src/libextra/stats.rs3
-rw-r--r--src/libextra/time.rs6
-rw-r--r--src/libextra/treemap.rs4
10 files changed, 30 insertions, 27 deletions
diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs
index f378384c564..f137b573c55 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 72b6e6dc650..dc65ef36b67 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<uint> 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 36ebf295aab..9ce5e2c7ba2 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<T> Deque<T> {
     /// Create an empty Deque with space for at least `n` elements.
     pub fn with_capacity(n: uint) -> Deque<T> {
         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 e0ed313bc02..fd80d8e0465 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 5867b13f556..13b55a4609b 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<BigUint, BigUint> 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<BigUint, BigUint> for BigUint {
 impl Sub<BigUint, BigUint> 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<BigUint, BigUint> 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<BigUint, BigUint> 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 d737698cfe2..8023fe2c5da 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<A:Copy + Send,B:Copy + Send>(
         ~[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<A:Copy + Send,B:Copy + Send>(
         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 f59a2414aae..68a678869da 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 0271b393f61..5446515c1ef 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 a64b2374328..d74656dcc2e 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 f2dea8b9bba..8fac055d26f 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<K: Ord + TotalOrd, V: Ord>(a: &TreeMap<K, V>,
     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; }