about summary refs log tree commit diff
path: root/src/libstd
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/libstd
parent5aa0ca9b2eb28166d9ab2e86557a5b1f84230b46 (diff)
parent20a2fbd05557b21b7e3f38d17250388a350d3484 (diff)
downloadrust-e388a80c234d628c4d1fab77dc3e3f2c04cbefc5.tar.gz
rust-e388a80c234d628c4d1fab77dc3e3f2c04cbefc5.zip
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/libstd')
-rw-r--r--src/libstd/hashmap.rs3
-rw-r--r--src/libstd/io.rs5
-rw-r--r--src/libstd/num/f32.rs64
-rw-r--r--src/libstd/num/f64.rs63
-rw-r--r--src/libstd/num/float.rs70
-rw-r--r--src/libstd/num/int_macros.rs66
-rw-r--r--src/libstd/num/num.rs39
-rw-r--r--src/libstd/num/uint_macros.rs42
-rw-r--r--src/libstd/rand.rs3
-rw-r--r--src/libstd/rand/distributions.rs25
-rw-r--r--src/libstd/unstable/extfmt.rs4
-rw-r--r--src/libstd/vec.rs4
12 files changed, 105 insertions, 283 deletions
diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs
index 2d80dc2be15..6c93cd0dc86 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<K:Eq + Hash,V>(
 fn linear_map_with_capacity_and_keys<K:Eq + Hash,V>(
     k0: u64, k1: u64,
     initial_capacity: uint) -> HashMap<K, V> {
-    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 38826dd411b..347fa988856 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 a84c27cd918..faf9b2e2390 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 216963e0414..c7db60e6fd2 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 d73ff16c6f7..486d3562089 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<float> 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 c2eebf9a3e4..75e0bbcb71b 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 b856c3c65ea..4468b51c261 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<T: Orderable>(a: T, b: T) -> T { a.min(&b) }
+#[inline(always)] pub fn max<T: Orderable>(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<T: Signed>(value: T) -> T { value.abs() }
+#[inline(always)] pub fn signum<T: Signed>(value: T) -> T { value.signum() }
 
-// This should be moved into the default implementation for Signed::abs
-pub fn abs<T:Ord + Zero + Neg<T>>(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<T: Algebraic>(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<T: Trigonometric>(value: T) -> T { value.sin() }
+#[inline(always)] pub fn cos<T: Trigonometric>(value: T) -> T { value.cos() }
+#[inline(always)] pub fn tan<T: Trigonometric>(value: T) -> T { value.tan() }
+
+#[inline(always)] pub fn asin<T: Trigonometric>(value: T) -> T { value.asin() }
+#[inline(always)] pub fn acos<T: Trigonometric>(value: T) -> T { value.acos() }
+#[inline(always)] pub fn atan<T: Trigonometric>(value: T) -> T { value.atan() }
+
+#[inline(always)] pub fn atan2<T: Trigonometric>(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<T: Exponential>(value: T) -> T { value.exp() }
+#[inline(always)] pub fn exp2<T: Exponential>(value: T) -> T { value.exp2() }
+
+#[inline(always)] pub fn ln<T: Exponential>(value: T) -> T { value.ln() }
+#[inline(always)] pub fn log<T: Exponential>(value: T, base: T) -> T { value.log(&base) }
+#[inline(always)] pub fn log2<T: Exponential>(value: T) -> T { value.log2() }
+#[inline(always)] pub fn log10<T: Exponential>(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<T: Hyperbolic>(value: T) -> T { value.sinh() }
+#[inline(always)] pub fn cosh<T: Hyperbolic>(value: T) -> T { value.cosh() }
+#[inline(always)] pub fn tanh<T: Hyperbolic>(value: T) -> T { value.tanh() }
+
+#[inline(always)] pub fn asinh<T: Hyperbolic>(value: T) -> T { value.asinh() }
+#[inline(always)] pub fn acosh<T: Hyperbolic>(value: T) -> T { value.acosh() }
+#[inline(always)] pub fn atanh<T: Hyperbolic>(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 d185b2a05a8..de1b997b14b 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 5054763d742..02c8694bf76 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<R: Rng> RngUtil for R {
      */
     fn gen_int_range(&mut self, start: int, end: int) -> int {
         assert!(start < end);
-        start + int::abs(self.gen::<int>() % (end - start))
+        start + num::abs(self.gen::<int>() % (end - start))
     }
 
     /**
diff --git a/src/libstd/rand/distributions.rs b/src/libstd/rand/distributions.rs
index e8dad2fc5e8..4d983b94954 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<R:Rng>(rng: &mut R,
         let i: uint = rng.gen::<uint>() & 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<R:Rng>(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<R:Rng>(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::<f64>().ln() / ziggurat_tables::ZIG_NORM_R;
+                y = rng.gen::<f64>().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::<f64>())` but that is slower.
+// This could be done via `-rng.gen::<f64>().ln()` but that is slower.
 impl Rand for Exp1 {
     #[inline]
     fn rand<R:Rng>(rng: &mut R) -> Exp1 {
         #[inline]
         fn pdf(x: f64) -> f64 {
-            f64::exp(-x)
+            (-x).exp()
         }
         #[inline]
         fn zero_case<R:Rng>(rng: &mut R, _u: f64) -> f64 {
-            ziggurat_tables::ZIG_EXP_R - f64::ln(rng.gen())
+            ziggurat_tables::ZIG_EXP_R - rng.gen::<f64>().ln()
         }
 
         Exp1(ziggurat(rng, false,
diff --git a/src/libstd/unstable/extfmt.rs b/src/libstd/unstable/extfmt.rs
index b1df5175c92..64ac76756d5 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 191c2a4a0b2..309973def80 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