Skip to content

Factoring bigint and rational out of libextra. #12141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
################################################################################

TARGET_CRATES := std extra green rustuv native flate arena glob term semver \
uuid serialize sync getopts collections fourcc
uuid serialize sync getopts collections fourcc bigint rational
HOST_CRATES := syntax rustc rustdoc
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
TOOLS := compiletest rustdoc rustc
Expand All @@ -75,6 +75,8 @@ DEPS_sync := std
DEPS_getopts := std
DEPS_collections := std serialize
DEPS_fourcc := syntax std
DEPS_bigint := std extra
DEPS_rational := std bigint

TOOL_DEPS_compiletest := extra green rustuv getopts
TOOL_DEPS_rustdoc := rustdoc green rustuv
Expand Down
2 changes: 2 additions & 0 deletions src/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ li {list-style-type: none; }
* [The Rust compiler, `librustc`](rustc/index.html)

* [The `arena` allocation library](arena/index.html)
* [The `bigint` arbitrary precision integer library](bigint/index.html)
* {The `rational` numeric library](rational/index.html)
* [The `collections` library](collections/index.html)
* [The `flate` compression library](flate/index.html)
* [The `getopts` argument parsing library](getopts/index.html)
Expand Down
10 changes: 5 additions & 5 deletions src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -3029,12 +3029,12 @@ In Rust terminology, we need a way to refer to other crates.
For that, Rust offers you the `extern mod` declaration:

~~~
extern mod extra;
// extra ships with Rust, you'll find more details further down.
extern mod rational;
// rational ships with Rust, you'll find more details further down.

fn main() {
// The rational number '1/2':
let one_half = ::extra::rational::Ratio::new(1, 2);
let one_half = ::rational::Ratio::new(1, 2);
}
~~~

Expand All @@ -3059,10 +3059,10 @@ of both `use` and local declarations.
Which can result in something like this:

~~~
extern mod extra;
extern mod rational;

use farm::dog;
use extra::rational::Ratio;
use rational::Ratio;

mod farm {
pub fn dog() { println!("woof"); }
Expand Down
17 changes: 13 additions & 4 deletions src/libextra/num/bigint.rs → src/libbigint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@ A `BigUint` is represented as an array of `BigDigit`s.
A `BigInt` is a combination of `BigUint` and `Sign`.
*/

#[feature(macro_rules)];

#[allow(missing_doc)];
#[allow(non_uppercase_statics)];

#[crate_id = "bigint#0.10-pre"];
#[crate_type = "rlib"];
#[crate_type = "dylib"];
#[license = "MIT/ASL2"];

extern mod extra;

use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
use std::num;
use std::num::{Zero, One, ToStrRadix, FromStrRadix, Orderable};
Expand Down Expand Up @@ -48,7 +57,7 @@ pub type BigDigit = u32;
pub static ZERO_BIG_DIGIT: BigDigit = 0;

pub mod BigDigit {
use bigint::BigDigit;
use super::BigDigit;

#[cfg(target_word_size = "32")]
pub static bits: uint = 16;
Expand Down Expand Up @@ -1433,7 +1442,7 @@ impl BigInt {

#[cfg(test)]
mod biguint_tests {
use super::*;
use super::{BigUint};
use super::RandBigInt;

use std::cmp::{Less, Equal, Greater};
Expand Down Expand Up @@ -2090,7 +2099,7 @@ mod biguint_tests {

#[cfg(test)]
mod bigint_tests {
use super::*;
use super::{BigInt};
use super::RandBigInt;

use std::cmp::{Less, Equal, Greater};
Expand Down Expand Up @@ -2591,7 +2600,7 @@ mod bigint_tests {

#[cfg(test)]
mod bench {
use super::*;
use super::{BigInt, BigUint};
use std::{iter, util};
use std::num::{FromPrimitive, Zero, One};
use extra::test::BenchHarness;
Expand Down
4 changes: 0 additions & 4 deletions src/libextra/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ pub mod time;
pub mod base64;
pub mod workcache;
pub mod enum_set;
#[path="num/bigint.rs"]
pub mod bigint;
#[path="num/rational.rs"]
pub mod rational;
#[path="num/complex.rs"]
pub mod complex;
pub mod stats;
Expand Down
18 changes: 13 additions & 5 deletions src/libextra/num/rational.rs → src/librational/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -10,11 +10,19 @@

//! Rational numbers

#[feature(macro_rules)];

#[crate_id = "rational#0.10-pre"];
#[crate_type = "rlib"];
#[crate_type = "dylib"];
#[license = "MIT/ASL2"];

extern mod bigint;

use std::cmp;
use std::from_str::FromStr;
use std::num::{Zero,One,ToStrRadix,FromStrRadix,Round};
use super::bigint::{BigInt, BigUint, Sign, Plus, Minus};
use bigint::{BigInt, BigUint, Sign, Plus, Minus};

/// Represents the ratio between 2 numbers.
#[deriving(Clone)]
Expand Down Expand Up @@ -349,7 +357,7 @@ impl<T: FromStrRadix + Clone + Integer + Ord>
#[cfg(test)]
mod test {

use super::*;
use super::{Rational};
use std::num::{Zero,One,FromStrRadix,FromPrimitive};
use std::from_str::FromStr;

Expand Down Expand Up @@ -449,8 +457,8 @@ mod test {


mod arith {
use super::*;
use super::super::*;
use super::{_0, _1, _2, _1_2, _3_2, _neg1_2};
use super::super::{Rational};


#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/test/bench/shootout-pidigits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern mod extra;
extern mod bigint;

use std::from_str::FromStr;
use std::num::One;
use std::num::Zero;
use std::num::FromPrimitive;
use extra::bigint::BigInt;
use bigint::BigInt;

struct Context {
numer: BigInt,
Expand Down