Upgrade to latest Rust

A `_0` test fails, but don’t know why
This commit is contained in:
Sven Nilsen 2015-01-03 19:30:05 +01:00
parent 522c97f3b8
commit ae3bb3619c
8 changed files with 35 additions and 18 deletions

View File

@ -42,7 +42,7 @@ extern crate num;
extern crate test;
use std::str::FromStr;
use std::num::FromPrimitive;
use std::num::{FromPrimitive, ToPrimitive};
use test::Bencher;

View File

@ -62,9 +62,12 @@ use std::iter::repeat;
use std::iter::{AdditiveIterator, MultiplicativeIterator};
use std::num::FromStrRadix;
use std::num::{Int, ToPrimitive, FromPrimitive};
use std::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Rem, Shl, Shr, Sub};
use std::rand::Rng;
use std::str::{mod, FromStr};
use std::str::{self, FromStr};
use std::{cmp, fmt, hash};
use std::cmp::Ordering;
use std::cmp::Ordering::{Less, Greater, Equal};
use std::{i64, u64};
use {Num, Unsigned, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv, Signed, Zero, One};
@ -78,7 +81,7 @@ pub type BigDigit = u32;
pub type DoubleBigDigit = u64;
pub const ZERO_BIG_DIGIT: BigDigit = 0;
static ZERO_VEC: [BigDigit, ..1] = [ZERO_BIG_DIGIT];
static ZERO_VEC: [BigDigit; 1] = [ZERO_BIG_DIGIT];
#[allow(non_snake_case)]
pub mod BigDigit {
@ -113,7 +116,7 @@ pub mod BigDigit {
///
/// A `BigUint`-typed value `BigUint { data: vec!(a, b, c) }` represents a number
/// `(a + b * BigDigit::BASE + c * BigDigit::BASE^2)`.
#[deriving(Clone, RustcEncodable, RustcDecodable)]
#[derive(Clone, RustcEncodable, RustcDecodable)]
pub struct BigUint {
data: Vec<BigDigit>
}
@ -933,7 +936,7 @@ fn get_radix_base(radix: uint) -> (DoubleBigDigit, uint) {
}
/// A Sign is a `BigInt`'s composing element.
#[deriving(PartialEq, PartialOrd, Eq, Ord, Copy, Clone, Show, RustcEncodable, RustcDecodable)]
#[derive(PartialEq, PartialOrd, Eq, Ord, Copy, Clone, Show, RustcEncodable, RustcDecodable)]
pub enum Sign { Minus, NoSign, Plus }
impl Neg<Sign> for Sign {
@ -949,7 +952,7 @@ impl Neg<Sign> for Sign {
}
/// A big signed integer type.
#[deriving(Clone, RustcEncodable, RustcDecodable)]
#[derive(Clone, RustcEncodable, RustcDecodable)]
pub struct BigInt {
sign: Sign,
data: BigUint
@ -1608,7 +1611,7 @@ mod biguint_tests {
#[test]
fn test_cmp() {
let data: [&[_], ..7] = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1] ];
let data: [&[_]; 7] = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1] ];
let data: Vec<BigUint> = data.iter().map(|v| BigUint::from_slice(*v)).collect();
for (i, ni) in data.iter().enumerate() {
for (j0, nj) in data.slice(i, data.len()).iter().enumerate() {
@ -2456,6 +2459,7 @@ mod bigint_tests {
use std::num::{ToPrimitive, FromPrimitive};
use std::rand::thread_rng;
use std::u64;
use std::ops::{Neg};
use {Zero, One, Signed};
@ -2474,7 +2478,7 @@ mod bigint_tests {
#[test]
fn test_cmp() {
let vs: [&[BigDigit], ..4] = [ &[2 as BigDigit], &[1, 1], &[2, 1], &[1, 1, 1] ];
let vs: [&[BigDigit]; 4] = [ &[2 as BigDigit], &[1, 1], &[2, 1], &[1, 1, 1] ];
let mut nums = Vec::new();
for s in vs.iter().rev() {
nums.push(BigInt::from_slice(Minus, *s));

View File

@ -14,6 +14,7 @@
use std::fmt;
use std::num::FloatMath;
use std::iter::{AdditiveIterator, MultiplicativeIterator};
use std::ops::{Add, Div, Mul, Neg, Sub};
use {Zero, One, Num};
@ -21,7 +22,7 @@ use {Zero, One, Num};
// probably doesn't map to C's _Complex correctly.
/// A complex number in Cartesian form.
#[deriving(PartialEq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
#[derive(PartialEq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
pub struct Complex<T> {
/// Real portion of the complex number
pub re: T,
@ -264,7 +265,7 @@ mod test {
pub const _0_1i : Complex64 = Complex { re: 0.0, im: 1.0 };
pub const _neg1_1i : Complex64 = Complex { re: -1.0, im: 1.0 };
pub const _05_05i : Complex64 = Complex { re: 0.5, im: 0.5 };
pub const all_consts : [Complex64, .. 5] = [_0_0i, _1_0i, _1_1i, _neg1_1i, _05_05i];
pub const all_consts : [Complex64; 5] = [_0_0i, _1_0i, _1_1i, _neg1_1i, _05_05i];
#[test]
fn test_consts() {

View File

@ -10,9 +10,11 @@
//! Integer trait and functions.
use std::ops::{Div, Rem};
use {Num, Signed};
pub trait Integer: Num + PartialOrd
pub trait Integer: Sized + Num + PartialOrd
+ Div<Self, Self>
+ Rem<Self, Self> {
/// Floored integer division.

View File

@ -11,10 +11,11 @@
//! External iterators for generic mathematics
use {Integer, Zero, One, CheckedAdd};
use std::num::Int;
use std::ops::{Add, Sub};
use std::num::{ToPrimitive, Int};
/// An iterator over the range [start, stop)
#[deriving(Clone)]
#[derive(Clone)]
pub struct Range<A> {
state: A,
stop: A,
@ -100,7 +101,7 @@ impl<A: Integer + PartialOrd + Clone + ToPrimitive> DoubleEndedIterator<A> for R
}
/// An iterator over the range [start, stop]
#[deriving(Clone)]
#[derive(Clone)]
pub struct RangeInclusive<A> {
range: Range<A>,
done: bool,
@ -163,7 +164,7 @@ impl<A: Sub<A, A> + Integer + PartialOrd + Clone + ToPrimitive> DoubleEndedItera
}
/// An iterator over the range [start, stop) by `step`. It handles overflow by stopping.
#[deriving(Clone)]
#[derive(Clone)]
pub struct RangeStep<A> {
state: A,
stop: A,
@ -196,7 +197,7 @@ impl<A: CheckedAdd + PartialOrd + Clone> Iterator<A> for RangeStep<A> {
}
/// An iterator over the range [start, stop] by `step`. It handles overflow by stopping.
#[deriving(Clone)]
#[derive(Clone)]
pub struct RangeStepInclusive<A> {
state: A,
stop: A,
@ -233,6 +234,9 @@ impl<A: CheckedAdd + PartialOrd + Clone + PartialEq> Iterator<A> for RangeStepIn
#[cfg(test)]
mod tests {
use std::uint;
use std::num::ToPrimitive;
use std::ops::{Add, Mul};
use std::cmp::Ordering;
use One;
#[test]

View File

@ -1,3 +1,5 @@
#![feature(old_orphan_check)]
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
@ -61,6 +63,8 @@ pub use iter::{range, range_inclusive, range_step, range_step_inclusive};
pub use traits::{Num, Zero, One, Signed, Unsigned, Bounded,
Saturating, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv};
use std::ops::{Mul};
pub mod bigint;
pub mod complex;
pub mod integer;

View File

@ -14,15 +14,16 @@ use Integer;
use std::cmp;
use std::fmt;
use std::ops::{Add, Div, Mul, Neg, Rem, Sub};
use std::str::FromStr;
use std::num::{FromStrRadix, Float};
use std::num::{FromPrimitive, FromStrRadix, Float};
use std::iter::{AdditiveIterator, MultiplicativeIterator};
use bigint::{BigInt, BigUint, Sign};
use {Num, Signed, Zero, One};
/// Represents the ratio between 2 numbers.
#[deriving(Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
#[derive(Copy, Clone, Hash, RustcEncodable, RustcDecodable)]
#[allow(missing_docs)]
pub struct Ratio<T> {
numer: T,

View File

@ -11,6 +11,7 @@
//! Numeric traits for generic mathematics
use std::intrinsics;
use std::ops::{Add, Div, Mul, Neg, Rem, Sub};
use std::{uint, u8, u16, u32, u64};
use std::{int, i8, i16, i32, i64};
use std::{f32, f64};