Skip to content

Commit d2d1129

Browse files
committed
Factoring bigint, rational, and complex out of libextra into libnum.
Removed use of globs present in earlier versions of modules. Fix tutorial.md to reflect `extra::rational` ==> `num::rational`.
1 parent 3794d68 commit d2d1129

File tree

9 files changed

+47
-33
lines changed

9 files changed

+47
-33
lines changed

mk/crates.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
################################################################################
5151

5252
TARGET_CRATES := std extra green rustuv native flate arena glob term semver \
53-
uuid serialize sync getopts collections
53+
uuid serialize sync getopts collections num
5454
HOST_CRATES := syntax rustc rustdoc fourcc
5555
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
5656
TOOLS := compiletest rustdoc rustc
@@ -75,6 +75,7 @@ DEPS_sync := std
7575
DEPS_getopts := std
7676
DEPS_collections := std serialize
7777
DEPS_fourcc := syntax std
78+
DEPS_num := std extra
7879

7980
TOOL_DEPS_compiletest := extra green rustuv getopts
8081
TOOL_DEPS_rustdoc := rustdoc green rustuv

src/doc/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ li {list-style-type: none; }
3838
* [The Rust compiler, `librustc`](rustc/index.html)
3939

4040
* [The `arena` allocation library](arena/index.html)
41+
* [The `num` arbitrary precision numerics library](num/index.html)
4142
* [The `collections` library](collections/index.html)
4243
* [The `flate` compression library](flate/index.html)
4344
* [The `fourcc` four-character code library](fourcc/index.html)

src/doc/tutorial.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -3026,12 +3026,12 @@ In Rust terminology, we need a way to refer to other crates.
30263026
For that, Rust offers you the `extern mod` declaration:
30273027

30283028
~~~
3029-
extern mod extra;
3030-
// extra ships with Rust, you'll find more details further down.
3029+
extern mod num;
3030+
// `num` ships with Rust (much like `extra`; more details further down).
30313031
30323032
fn main() {
30333033
// The rational number '1/2':
3034-
let one_half = ::extra::rational::Ratio::new(1, 2);
3034+
let one_half = ::num::rational::Ratio::new(1, 2);
30353035
}
30363036
~~~
30373037

@@ -3056,10 +3056,10 @@ of both `use` and local declarations.
30563056
Which can result in something like this:
30573057

30583058
~~~
3059-
extern mod extra;
3059+
extern mod num;
30603060
30613061
use farm::dog;
3062-
use extra::rational::Ratio;
3062+
use num::rational::Ratio;
30633063
30643064
mod farm {
30653065
pub fn dog() { println!("woof"); }
@@ -3224,9 +3224,9 @@ See the [API documentation][stddoc] for details.
32243224

32253225
## The extra library
32263226

3227-
Rust also ships with the [extra library], an accumulation of useful things,
3227+
Rust ships with crates such as the [extra library], an accumulation of useful things,
32283228
that are however not important enough to deserve a place in the standard
3229-
library. You can use them by linking to `extra` with an `extern mod extra;`.
3229+
library. You can link to a library such as `extra` with an `extern mod extra;`.
32303230

32313231
[extra library]: extra/index.html
32323232

src/libextra/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ pub mod time;
6262
pub mod base64;
6363
pub mod workcache;
6464
pub mod enum_set;
65-
#[path="num/bigint.rs"]
66-
pub mod bigint;
67-
#[path="num/rational.rs"]
68-
pub mod rational;
69-
#[path="num/complex.rs"]
70-
pub mod complex;
7165
pub mod stats;
7266
pub mod hex;
7367

src/libextra/num/bigint.rs renamed to src/libnum/bigint.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ A `BigUint` is represented as an array of `BigDigit`s.
1616
A `BigInt` is a combination of `BigUint` and `Sign`.
1717
*/
1818

19-
#[allow(missing_doc)];
20-
#[allow(non_uppercase_statics)];
21-
2219
use std::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater};
2320
use std::num;
2421
use std::num::{Zero, One, ToStrRadix, FromStrRadix, Orderable};
@@ -48,7 +45,7 @@ pub type BigDigit = u32;
4845
pub static ZERO_BIG_DIGIT: BigDigit = 0;
4946

5047
pub mod BigDigit {
51-
use bigint::BigDigit;
48+
use super::BigDigit;
5249

5350
#[cfg(target_word_size = "32")]
5451
pub static bits: uint = 16;
@@ -1433,8 +1430,8 @@ impl BigInt {
14331430
14341431
#[cfg(test)]
14351432
mod biguint_tests {
1436-
use super::*;
1437-
use super::RandBigInt;
1433+
use super::{BigDigit, BigUint, ToBigUint};
1434+
use super::{Plus, BigInt, RandBigInt, ToBigInt};
14381435
14391436
use std::cmp::{Less, Equal, Greater};
14401437
use std::i64;
@@ -2090,8 +2087,8 @@ mod biguint_tests {
20902087

20912088
#[cfg(test)]
20922089
mod bigint_tests {
2093-
use super::*;
2094-
use super::RandBigInt;
2090+
use super::{BigDigit, BigUint, ToBigUint};
2091+
use super::{Sign, Minus, Zero, Plus, BigInt, RandBigInt, ToBigInt};
20952092

20962093
use std::cmp::{Less, Equal, Greater};
20972094
use std::i64;
@@ -2591,7 +2588,7 @@ mod bigint_tests {
25912588

25922589
#[cfg(test)]
25932590
mod bench {
2594-
use super::*;
2591+
use super::{BigInt, BigUint};
25952592
use std::iter;
25962593
use std::mem::replace;
25972594
use std::num::{FromPrimitive, Zero, One};

src/libextra/num/complex.rs renamed to src/libnum/complex.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<T: ToStrRadix + Num + Ord> ToStrRadix for Cmplx<T> {
191191
mod test {
192192
#[allow(non_uppercase_statics)];
193193

194-
use super::*;
194+
use super::{Complex64, Cmplx};
195195
use std::num::{Zero,One,Real};
196196

197197
pub static _0_0i : Complex64 = Cmplx { re: 0.0, im: 0.0 };
@@ -285,7 +285,7 @@ mod test {
285285
}
286286

287287
mod arith {
288-
use super::*;
288+
use super::{_0_0i, _1_0i, _1_1i, _0_1i, _neg1_1i, _05_05i, all_consts};
289289
use std::num::Zero;
290290

291291
#[test]

src/libnum/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[feature(macro_rules)];
12+
13+
#[crate_id = "num#0.10-pre"];
14+
#[crate_type = "rlib"];
15+
#[crate_type = "dylib"];
16+
#[license = "MIT/ASL2"];
17+
18+
extern mod extra;
19+
20+
pub mod bigint;
21+
pub mod rational;
22+
pub mod complex;

src/libextra/num/rational.rs renamed to src/libnum/rational.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -10,11 +10,10 @@
1010

1111
//! Rational numbers
1212
13-
1413
use std::cmp;
1514
use std::from_str::FromStr;
1615
use std::num::{Zero,One,ToStrRadix,FromStrRadix,Round};
17-
use super::bigint::{BigInt, BigUint, Sign, Plus, Minus};
16+
use bigint::{BigInt, BigUint, Sign, Plus, Minus};
1817

1918
/// Represents the ratio between 2 numbers.
2019
#[deriving(Clone)]
@@ -349,7 +348,7 @@ impl<T: FromStrRadix + Clone + Integer + Ord>
349348
#[cfg(test)]
350349
mod test {
351350

352-
use super::*;
351+
use super::{Ratio, Rational, BigRational};
353352
use std::num::{Zero,One,FromStrRadix,FromPrimitive};
354353
use std::from_str::FromStr;
355354

@@ -449,8 +448,8 @@ mod test {
449448

450449

451450
mod arith {
452-
use super::*;
453-
use super::super::*;
451+
use super::{_0, _1, _2, _1_2, _3_2, _neg1_2, to_big};
452+
use super::super::{Ratio, Rational, BigRational};
454453

455454

456455
#[test]

src/test/bench/shootout-pidigits.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
extern mod extra;
11+
extern mod num;
1212

1313
use std::from_str::FromStr;
1414
use std::num::One;
1515
use std::num::Zero;
1616
use std::num::FromPrimitive;
17-
use extra::bigint::BigInt;
17+
use num::bigint::BigInt;
1818

1919
struct Context {
2020
numer: BigInt,

0 commit comments

Comments
 (0)