      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113

    // Copyright 2014-2016 The Rust Project Developers. See the COPYRIGHT
    // file at the top-level directory of this distribution and at
    // http://rust-lang.org/COPYRIGHT.
    //
    // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
    // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
    // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
    // option. This file may not be copied, modified, or distributed
    // except according to those terms.

    //! A collection of numeric types and traits for Rust.
    //!
    //! This includes new types for big integers, rationals, and complex numbers,
    //! new traits for generic programming on numeric properties like `Integer`,
    //! and generic range iterators.
    //!
    //! ## Example
    //!
    //! This example uses the BigRational type and [Newton's method][newt] to
    //! approximate a square root to arbitrary precision:
    //!
    //! ```
    //! extern crate num;
    //! # #[cfg(all(feature = "bigint", feature="rational"))]
    //! # mod test {
    //!
    //! use num::FromPrimitive;
    //! use num::bigint::BigInt;
    //! use num::rational::{Ratio, BigRational};
    //!
    //! # pub
    //! fn approx_sqrt(number: u64, iterations: usize) -> BigRational {
    //!     let start: Ratio<BigInt> = Ratio::from_integer(FromPrimitive::from_u64(number).unwrap());
    //!     let mut approx = start.clone();
    //!
    //!     for _ in 0..iterations {
    //!         approx = (&approx + (&start / &approx)) /
    //!             Ratio::from_integer(FromPrimitive::from_u64(2).unwrap());
    //!     }
    //!
    //!     approx
    //! }
    //! # }
    //! # #[cfg(not(all(feature = "bigint", feature="rational")))]
    //! # mod test { pub fn approx_sqrt(n: u64, _: usize) -> u64 { n } }
    //! # use test::approx_sqrt;
    //!
    //! fn main() {
    //!     println!("{}", approx_sqrt(10, 4)); // prints 4057691201/1283082416
    //! }
    //!
    //! ```
    //!
    //! [newt]: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
    //!
    //! ## Compatibility
    //!
    //! The `num` crate is tested for rustc 1.8 and greater.

    #![doc(html_root_url = "https://docs.rs/num/0.1")]

    extern crate num_traits;
    extern crate num_integer;
    extern crate num_iter;
    #[cfg(feature = "num-complex")]
    extern crate num_complex;
    #[cfg(feature = "num-bigint")]
    extern crate num_bigint;
    #[cfg(feature = "num-rational")]
    extern crate num_rational;

    #[cfg(feature = "num-bigint")]
    pub use num_bigint::{BigInt, BigUint};
    #[cfg(feature = "num-rational")]
    pub use num_rational::Rational;
    #[cfg(all(feature = "num-rational", feature="num-bigint"))]
    pub use num_rational::BigRational;
    #[cfg(feature = "num-complex")]
    pub use num_complex::Complex;
    pub use num_integer::Integer;
    pub use num_iter::{range, range_inclusive, range_step, range_step_inclusive};
    pub use num_traits::{Num, Zero, One, Signed, Unsigned, Bounded,
                         one, zero, abs, abs_sub, signum,
                         Saturating, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv,
                         PrimInt, Float, ToPrimitive, FromPrimitive, NumCast, cast,
                         pow, checked_pow, clamp};

    #[cfg(feature = "num-bigint")]
    pub mod bigint {
        pub use num_bigint::*;
    }

    #[cfg(feature = "num-complex")]
    pub mod complex {
        pub use num_complex::*;
    }

    pub mod integer {
        pub use num_integer::*;
    }

    pub mod iter {
        pub use num_iter::*;
    }

    pub mod traits {
        pub use num_traits::*;
    }

    #[cfg(feature = "num-rational")]
    pub mod rational {
        pub use num_rational::*;
    }

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)