diff --git a/.travis.yml b/.travis.yml index 7dba5d6..720e38d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,15 @@ -install: - - curl https://static.rust-lang.org/rustup.sh | sudo sh - +language: rust script: - cargo build --verbose - cargo test --verbose + - cargo doc +after_success: | + [ $TRAVIS_BRANCH = master ] && + [ $TRAVIS_PULL_REQUEST = false ] && + echo '' > target/doc/index.html && + sudo pip install ghp-import && + ghp-import -n target/doc && + git push -fq https://${TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages env: - - LD_LIBRARY_PATH=/usr/local/lib + global: + secure: NNQ8QgQFZ05OhljZiuCg39AEPU7Yhko/shFlJG1lqYFoFrELibSmBPd7zJsTubufHRddn0ed6IH7qPLnzWJ/cS+dxwAopuqCFzGMOcd/JW8DJgD5PUBA8EVh8x0tNFJVxxdnGac1ufRneWMvMIxH2hO1DMc+8FZBBd7u1DNG1Lk= diff --git a/Cargo.toml b/Cargo.toml index e57651d..7fd6144 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "num" -version = "0.1.2" +version = "0.1.3" authors = ["The Rust Project Developers"] license = "MIT/Apache-2.0" homepage = "https://github.com/rust-lang/num" @@ -11,3 +11,6 @@ description = """ Simple numerics. This crate contains basic arbitrary-sized integer, rational, and complex types. """ + +[dependencies] +rustc-serialize = "0.1" diff --git a/src/bigint.rs b/src/bigint.rs index 67b928c..066c6eb 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -56,14 +56,15 @@ //! ``` use Integer; -use rand::Rng; -use std::{cmp, fmt, hash}; use std::default::Default; +use std::iter::repeat; use std::iter::{AdditiveIterator, MultiplicativeIterator}; -use std::num::{Int, ToPrimitive, FromPrimitive}; use std::num::FromStrRadix; +use std::num::{Int, ToPrimitive, FromPrimitive}; +use std::rand::Rng; use std::str::{mod, FromStr}; +use std::{cmp, fmt, hash}; use std::{i64, u64}; use {Num, Unsigned, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv, Signed, Zero, One}; @@ -112,7 +113,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, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct BigUint { data: Vec } @@ -759,7 +760,7 @@ fn to_str_radix(me: &BigUint, radix: uint) -> String { let mut s = String::with_capacity(v.len() * l); for n in v.iter().rev() { let ss = fmt::radix(*n as uint, radix as u8).to_string(); - s.push_str("0".repeat(l - ss.len())[]); + s.extend(repeat("0").take(l - ss.len())); s.push_str(ss[]); } s.trim_left_chars('0').to_string() @@ -932,7 +933,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, Encodable, Decodable)] +#[deriving(PartialEq, PartialOrd, Eq, Ord, Copy, Clone, Show, RustcEncodable, RustcDecodable)] pub enum Sign { Minus, NoSign, Plus } impl Neg for Sign { @@ -948,7 +949,7 @@ impl Neg for Sign { } /// A big signed integer type. -#[deriving(Clone, Encodable, Decodable)] +#[deriving(Clone, RustcEncodable, RustcDecodable)] pub struct BigInt { sign: Sign, data: BigUint @@ -1581,13 +1582,14 @@ mod biguint_tests { use super::Sign::Plus; use std::cmp::Ordering::{Less, Equal, Greater}; - use std::str::FromStr; + use std::hash::hash; use std::i64; + use std::iter::repeat; use std::num::FromStrRadix; use std::num::{ToPrimitive, FromPrimitive}; use std::rand::task_rng; + use std::str::FromStr; use std::u64; - use std::hash::hash; use {Zero, One, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv}; @@ -2284,25 +2286,25 @@ mod biguint_tests { (16, "fff".to_string()) )), ( BigUint::from_slice(&[ 1, 2 ]), vec!( (2, - format!("10{}1", "0".repeat(bits - 1))), + format!("10{}1", repeat("0").take(bits - 1).collect::())), (4, - format!("2{}1", "0".repeat(bits / 2 - 1))), + format!("2{}1", repeat("0").take(bits / 2 - 1).collect::())), (10, match bits { 32 => "8589934593".to_string(), 16 => "131073".to_string(), _ => panic!() }), (16, - format!("2{}1", "0".repeat(bits / 4 - 1))) + format!("2{}1", repeat("0").take(bits / 4 - 1).collect::())) )), ( BigUint::from_slice(&[ 1, 2, 3 ]), vec!( (2, format!("11{}10{}1", - "0".repeat(bits - 2), - "0".repeat(bits - 1))), + repeat("0").take(bits - 2).collect::(), + repeat("0").take(bits - 1).collect::())), (4, format!("3{}2{}1", - "0".repeat(bits / 2 - 1), - "0".repeat(bits / 2 - 1))), + repeat("0").take(bits / 2 - 1).collect::(), + repeat("0").take(bits / 2 - 1).collect::())), (10, match bits { 32 => "55340232229718589441".to_string(), 16 => "12885032961".to_string(), @@ -2310,8 +2312,8 @@ mod biguint_tests { }), (16, format!("3{}2{}1", - "0".repeat(bits / 4 - 1), - "0".repeat(bits / 4 - 1))) + repeat("0").take(bits / 4 - 1).collect::(), + repeat("0").take(bits / 4 - 1).collect::())) )) ) } @@ -2447,12 +2449,13 @@ mod bigint_tests { use super::Sign::{Minus, NoSign, Plus}; use std::cmp::Ordering::{Less, Equal, Greater}; + use std::hash::hash; use std::i64; + use std::iter::repeat; use std::num::FromStrRadix; use std::num::{ToPrimitive, FromPrimitive}; use std::rand::task_rng; use std::u64; - use std::hash::hash; use {Zero, One, Signed}; @@ -2972,7 +2975,7 @@ mod bigint_tests { // issue 10522, this hit an edge case that caused it to // attempt to allocate a vector of size (-1u) == huge. let x: BigInt = - from_str(format!("1{}", "0".repeat(36)).as_slice()).unwrap(); + format!("1{}", repeat("0").take(36).collect::()).parse().unwrap(); let _y = x.to_string(); } diff --git a/src/complex.rs b/src/complex.rs index 446ea09..ae900ec 100644 --- a/src/complex.rs +++ b/src/complex.rs @@ -21,7 +21,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, Encodable, Decodable)] +#[deriving(PartialEq, Copy, Clone, Hash, RustcEncodable, RustcDecodable)] pub struct Complex { /// Real portion of the complex number pub re: T, diff --git a/src/lib.rs b/src/lib.rs index 9523fc3..d1cbfa4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -45,18 +45,13 @@ #![feature(macro_rules)] #![feature(default_type_params)] #![feature(slicing_syntax)] - -#![crate_name = "num"] -#![experimental] -#![crate_type = "rlib"] -#![crate_type = "dylib"] +#![cfg_attr(test, deny(warnings))] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "http://www.rust-lang.org/favicon.ico", - html_root_url = "http://doc.rust-lang.org/master/", + html_root_url = "http://doc.rust-lang.org/num/", html_playground_url = "http://play.rust-lang.org/")] -extern crate rand; -extern crate serialize; +extern crate "rustc-serialize" as rustc_serialize; pub use bigint::{BigInt, BigUint}; pub use rational::{Rational, BigRational}; diff --git a/src/rational.rs b/src/rational.rs index 6058085..232031e 100644 --- a/src/rational.rs +++ b/src/rational.rs @@ -22,7 +22,7 @@ use bigint::{BigInt, BigUint, Sign}; use {Num, Signed, Zero, One}; /// Represents the ratio between 2 numbers. -#[deriving(Copy, Clone, Hash, Encodable, Decodable)] +#[deriving(Copy, Clone, Hash, RustcEncodable, RustcDecodable)] #[allow(missing_docs)] pub struct Ratio { numer: T,