]> git.lizzy.rs Git - rust.git/blob - src/libnum/lib.rs
auto merge of #17249 : vadimcn/rust/env-keys, r=alexcrichton
[rust.git] / src / libnum / lib.rs
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 //! Simple numerics.
12 //!
13 //! This crate contains arbitrary-sized integer, rational, and complex types.
14 //!
15 //! ## Example
16 //!
17 //! This example uses the BigRational type and [Newton's method][newt] to
18 //! approximate a square root to arbitrary precision:
19 //!
20 //! ```
21 //! # #![allow(deprecated)]
22 //! extern crate num;
23 //!
24 //! use num::bigint::BigInt;
25 //! use num::rational::{Ratio, BigRational};
26 //!
27 //! fn approx_sqrt(number: u64, iterations: uint) -> BigRational {
28 //!     let start: Ratio<BigInt> = Ratio::from_integer(FromPrimitive::from_u64(number).unwrap());
29 //!     let mut approx = start.clone();
30 //!
31 //!     for _ in range(0, iterations) {
32 //!         approx = (approx + (start / approx)) /
33 //!             Ratio::from_integer(FromPrimitive::from_u64(2).unwrap());
34 //!     }
35 //!
36 //!     approx
37 //! }
38 //!
39 //! fn main() {
40 //!     println!("{}", approx_sqrt(10, 4)); // prints 4057691201/1283082416
41 //! }
42 //! ```
43 //!
44 //! [newt]: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
45
46 #![feature(macro_rules)]
47 #![feature(default_type_params)]
48
49 #![crate_name = "num"]
50 #![deprecated = "This is now a cargo package located at: \
51                  https://github.com/rust-lang/num"]
52 #![allow(deprecated)]
53 #![crate_type = "rlib"]
54 #![crate_type = "dylib"]
55 #![license = "MIT/ASL2"]
56 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
57        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
58        html_root_url = "http://doc.rust-lang.org/master/",
59        html_playground_url = "http://play.rust-lang.org/")]
60 #![allow(deprecated)] // from_str_radix
61
62 extern crate rand;
63
64 pub use bigint::{BigInt, BigUint};
65 pub use rational::{Rational, BigRational};
66 pub use complex::Complex;
67 pub use integer::Integer;
68
69 pub mod bigint;
70 pub mod complex;
71 pub mod integer;
72 pub mod rational;