about summary refs log tree commit diff
path: root/src/libextra/num
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/num
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/num')
-rw-r--r--src/libextra/num/bigint.rs17
1 files changed, 9 insertions, 8 deletions
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
         }
     }