Update to rust master

This commit is contained in:
Alex Crichton 2015-03-19 09:57:18 -07:00
parent bc9698c504
commit 9848257eae
2 changed files with 17 additions and 47 deletions

View File

@ -2618,7 +2618,7 @@ mod biguint_tests {
fn test_factor() { fn test_factor() {
fn factor(n: usize) -> BigUint { fn factor(n: usize) -> BigUint {
let mut f: BigUint = One::one(); let mut f: BigUint = One::one();
for i in range(2, n + 1) { for i in 2..n + 1 {
// FIXME(#5992): assignment operator overloads // FIXME(#5992): assignment operator overloads
// f *= FromPrimitive::from_usize(i); // f *= FromPrimitive::from_usize(i);
let bu: BigUint = FromPrimitive::from_usize(i).unwrap(); let bu: BigUint = FromPrimitive::from_usize(i).unwrap();
@ -2667,7 +2667,7 @@ mod biguint_tests {
fn test_rand_range() { fn test_rand_range() {
let mut rng = thread_rng(); let mut rng = thread_rng();
for _ in range(0, 10) { for _ in 0..10 {
assert_eq!(rng.gen_bigint_range(&FromPrimitive::from_usize(236).unwrap(), assert_eq!(rng.gen_bigint_range(&FromPrimitive::from_usize(236).unwrap(),
&FromPrimitive::from_usize(237).unwrap()), &FromPrimitive::from_usize(237).unwrap()),
FromPrimitive::from_usize(236).unwrap()); FromPrimitive::from_usize(236).unwrap());
@ -2675,7 +2675,7 @@ mod biguint_tests {
let l = FromPrimitive::from_usize(403469000 + 2352).unwrap(); let l = FromPrimitive::from_usize(403469000 + 2352).unwrap();
let u = FromPrimitive::from_usize(403469000 + 3513).unwrap(); let u = FromPrimitive::from_usize(403469000 + 3513).unwrap();
for _ in range(0, 1000) { for _ in 0..1000 {
let n: BigUint = rng.gen_biguint_below(&u); let n: BigUint = rng.gen_biguint_below(&u);
assert!(n < u); assert!(n < u);
@ -3329,7 +3329,7 @@ mod bigint_tests {
fn test_rand_range() { fn test_rand_range() {
let mut rng = thread_rng(); let mut rng = thread_rng();
for _ in range(0, 10) { for _ in 0..10 {
assert_eq!(rng.gen_bigint_range(&FromPrimitive::from_usize(236).unwrap(), assert_eq!(rng.gen_bigint_range(&FromPrimitive::from_usize(236).unwrap(),
&FromPrimitive::from_usize(237).unwrap()), &FromPrimitive::from_usize(237).unwrap()),
FromPrimitive::from_usize(236).unwrap()); FromPrimitive::from_usize(236).unwrap());
@ -3337,7 +3337,7 @@ mod bigint_tests {
fn check(l: BigInt, u: BigInt) { fn check(l: BigInt, u: BigInt) {
let mut rng = thread_rng(); let mut rng = thread_rng();
for _ in range(0, 1000) { for _ in 0..1000 {
let n: BigInt = rng.gen_bigint_range(&l, &u); let n: BigInt = rng.gen_bigint_range(&l, &u);
assert!(n >= l); assert!(n >= l);
assert!(n < u); assert!(n < u);
@ -3391,7 +3391,7 @@ mod bench {
fn fib(n: usize) -> BigUint { fn fib(n: usize) -> BigUint {
let mut f0: BigUint = Zero::zero(); let mut f0: BigUint = Zero::zero();
let mut f1: BigUint = One::one(); let mut f1: BigUint = One::one();
for _ in range(0, n) { for _ in 0..n {
let f2 = f0 + &f1; let f2 = f0 + &f1;
f0 = replace(&mut f1, f2); f0 = replace(&mut f1, f2);
} }
@ -3429,7 +3429,7 @@ mod bench {
let n = { let one : BigUint = One::one(); one << 1000 }; let n = { let one : BigUint = One::one(); one << 1000 };
b.iter(|| { b.iter(|| {
let mut m = n.clone(); let mut m = n.clone();
for _ in range(0, 10) { for _ in 0..10 {
m = m >> 1; m = m >> 1;
} }
}) })

View File

@ -323,17 +323,11 @@ impl<T: CheckedAdd + CheckedSub + Zero + PartialOrd + Bounded> Saturating for T
} }
} }
/// Performs addition that returns `None` instead of wrapping around on overflow. /// Performs addition that returns `None` instead of wrapping around on
/// overflow.
pub trait CheckedAdd: Add<Self, Output = Self> { pub trait CheckedAdd: Add<Self, Output = Self> {
/// Adds two numbers, checking for overflow. If overflow happens, `None` is returned. /// Adds two numbers, checking for overflow. If overflow happens, `None` is
/// /// returned.
/// # Example
///
/// ```rust
/// use num::CheckedAdd;
/// assert_eq!(5u16.checked_add(&65530), Some(65535));
/// assert_eq!(6u16.checked_add(&65530), None);
/// ```
fn checked_add(&self, v: &Self) -> Option<Self>; fn checked_add(&self, v: &Self) -> Option<Self>;
} }
@ -386,15 +380,8 @@ checked_impl!(CheckedAdd, checked_add, i64, intrinsics::i64_add_with_overflow);
/// Performs subtraction that returns `None` instead of wrapping around on underflow. /// Performs subtraction that returns `None` instead of wrapping around on underflow.
pub trait CheckedSub: Sub<Self, Output = Self> { pub trait CheckedSub: Sub<Self, Output = Self> {
/// Subtracts two numbers, checking for underflow. If underflow happens, `None` is returned. /// Subtracts two numbers, checking for underflow. If underflow happens,
/// /// `None` is returned.
/// # Example
///
/// ```rust
/// use num::CheckedSub;
/// assert_eq!((-127i8).checked_sub(&1), Some(-128));
/// assert_eq!((-128i8).checked_sub(&1), None);
/// ```
fn checked_sub(&self, v: &Self) -> Option<Self>; fn checked_sub(&self, v: &Self) -> Option<Self>;
} }
@ -421,16 +408,8 @@ checked_impl!(CheckedSub, checked_sub, i64, intrinsics::i64_sub_with_overflow);
/// Performs multiplication that returns `None` instead of wrapping around on underflow or /// Performs multiplication that returns `None` instead of wrapping around on underflow or
/// overflow. /// overflow.
pub trait CheckedMul: Mul<Self, Output = Self> { pub trait CheckedMul: Mul<Self, Output = Self> {
/// Multiplies two numbers, checking for underflow or overflow. If underflow or overflow /// Multiplies two numbers, checking for underflow or overflow. If underflow
/// happens, `None` is returned. /// or overflow happens, `None` is returned.
///
/// # Example
///
/// ```rust
/// use num::CheckedMul;
/// assert_eq!(5u8.checked_mul(&51), Some(255));
/// assert_eq!(5u8.checked_mul(&52), None);
/// ```
fn checked_mul(&self, v: &Self) -> Option<Self>; fn checked_mul(&self, v: &Self) -> Option<Self>;
} }
@ -457,17 +436,8 @@ checked_impl!(CheckedMul, checked_mul, i64, intrinsics::i64_mul_with_overflow);
/// Performs division that returns `None` instead of panicking on division by zero and instead of /// Performs division that returns `None` instead of panicking on division by zero and instead of
/// wrapping around on underflow and overflow. /// wrapping around on underflow and overflow.
pub trait CheckedDiv: Div<Self, Output = Self> { pub trait CheckedDiv: Div<Self, Output = Self> {
/// Divides two numbers, checking for underflow, overflow and division by zero. If any of that /// Divides two numbers, checking for underflow, overflow and division by
/// happens, `None` is returned. /// zero. If any of that happens, `None` is returned.
///
/// # Example
///
/// ```rust
/// use num::CheckedDiv;
/// assert_eq!((-127i8).checked_div(&-1), Some(127));
/// assert_eq!((-128i8).checked_div(&-1), None);
/// assert_eq!((1i8).checked_div(&0), None);
/// ```
fn checked_div(&self, v: &Self) -> Option<Self>; fn checked_div(&self, v: &Self) -> Option<Self>;
} }