diff --git a/benches/shootout-pidigits.rs b/benches/shootout-pidigits.rs index 0090db8..93ed28c 100644 --- a/benches/shootout-pidigits.rs +++ b/benches/shootout-pidigits.rs @@ -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; diff --git a/src/bigint.rs b/src/bigint.rs index b0b2195..d988959 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -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 } @@ -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 for Sign { @@ -949,7 +952,7 @@ impl Neg 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 = 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)); diff --git a/src/complex.rs b/src/complex.rs index ae900ec..e3872d7 100644 --- a/src/complex.rs +++ b/src/complex.rs @@ -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 { /// 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() { diff --git a/src/integer.rs b/src/integer.rs index fbfd196..006ea3c 100644 --- a/src/integer.rs +++ b/src/integer.rs @@ -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 + Rem { /// Floored integer division. diff --git a/src/iter.rs b/src/iter.rs index 7e4a04a..fd75721 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -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 { state: A, stop: A, @@ -100,7 +101,7 @@ impl DoubleEndedIterator for R } /// An iterator over the range [start, stop] -#[deriving(Clone)] +#[derive(Clone)] pub struct RangeInclusive { range: Range, done: bool, @@ -163,7 +164,7 @@ impl + 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 { state: A, stop: A, @@ -196,7 +197,7 @@ impl Iterator for RangeStep { } /// An iterator over the range [start, stop] by `step`. It handles overflow by stopping. -#[deriving(Clone)] +#[derive(Clone)] pub struct RangeStepInclusive { state: A, stop: A, @@ -233,6 +234,9 @@ impl Iterator 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] diff --git a/src/lib.rs b/src/lib.rs index d1cbfa4..51e74be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/rational.rs b/src/rational.rs index 232031e..7bb587b 100644 --- a/src/rational.rs +++ b/src/rational.rs @@ -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 { numer: T, diff --git a/src/traits.rs b/src/traits.rs index a930af2..a0b77fb 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -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};