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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright © 2016–2017 University of Malta

// This program is free software: you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License and a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.

//! # Arbitrary-precision numbers
//!
//! The `rug` crate provides integers and floating-point numbers with
//! arbitrary precision and correct rounding. Its main features are:
//!
//! * big [integers][rug int] with arbitrary precision,
//! * big [rational numbers][rug rat] with arbitrary precision,
//! * multi-precision [floating-point numbers][rug flo] with correct
//!   rounding, and
//! * multi-precision [complex numbers][rug com] with correct
//!   rounding.
//!
//! This crate is free software: you can redistribute it and/or modify
//! it under the terms of the GNU Lesser General Public License as
//! published by the Free Software Foundation, either version 3 of the
//! License, or (at your option) any later version. See the full text
//! of the [GNU LGPL][lgpl] and [GNU GPL][gpl] for details.
//!
//! ## Basic use
//!
//! This crate depends on the low-level bindings in the
//! [`gmp-mpfr-sys`][sys] crate, which provides RUST FFI bindings for:
//!
//! * the [GNU Multiple Precision Arithmetic Library][gmp home] (GMP),
//! * the [GNU MPFR Library][mpfr home], a library for
//!   multiple-precision floating-point computations, and
//! * [GNU MPC][mpc home], a library for the arithmetic of complex
//!   numbers with arbitrarily high precision.
//!
//! It can be helpful to refer to the documentation of the [GMP][gmp],
//! [MPFR][mpfr] and [MPC][mpc] libraries.
//!
//! ## Examples
//!
//! ```rust
//! extern crate rug;
//! use rug::{Assign, Integer};
//!
//! fn main() {
//!     // Create an integer initialized as zero.
//!     let mut int = Integer::new();
//!     assert_eq!(int, 0);
//!     int.assign(14);
//!     assert_eq!(int, 14);
//!     let hex_160 = "ffff0000ffff0000ffff0000ffff0000ffff0000";
//!     int.assign_str_radix(hex_160, 16).unwrap();
//!     assert_eq!(int.significant_bits(), 160);
//!     int = (int >> 128) - 1;
//!     assert_eq!(int, 0xfffe_ffff_u32);
//! }
//! ```
//!
//! ## Usage
//!
//! To use `rug` in your crate, add `extern crate rug;` to the crate
//! root and add `rug` as a dependency in `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! rug = "0.4.0"
//! ```
//!
//! The `rug` crate depends on the low-level bindings in the
//! `gmp-mpfr-sys` crate. This should be transparent on GNU/Linux and
//! macOS, but may need some work on Windows. See the `gmp-mpfr-sys`
//! [documentation][sys] for some details.
//!
//! ### Optional feature
//!
//! The `rug` crate has three optional features `rational`, `float`
//! and `complex`. Integers are always included. The optional features
//! are enabled by default; to disable them add this to `Cargo.toml`:
//!
//! ```toml
//! [dependencies.rug]
//! version = "0.4.0"
//! default-features = false
//! ```
//!
//! To use features selectively, you can add this to `Cargo.toml`:
//!
//! ```toml
//! [dependencies.rug]
//! version = "0.4.0"
//! default-features = false
//! # Pick which features to use
//! features = ["rational", "float"]
//! ```
//!
//! Note that the the `complex` feature will enable the `float`
//! feature, on which it depends.
//!
//! [gmp home]:  https://gmplib.org/
//! [gmp]:       https://tspiteri.gitlab.io/rug/gmp/index.html
//! [gpl]:       https://www.gnu.org/licenses/gpl-3.0.html
//! [lgpl]:      https://www.gnu.org/licenses/lgpl-3.0.en.html
//! [mpc home]:  http://www.multiprecision.org/
//! [mpc]:       https://tspiteri.gitlab.io/rug/mpc/index.html
//! [mpfr home]: http://www.mpfr.org/
//! [mpfr]:      https://tspiteri.gitlab.io/rug/mpfr/index.html
//! [rug com]:   struct.Complex.html
//! [rug flo]:   struct.Float.html
//! [rug int]:   struct.Integer.html
//! [rug rat]:   struct.Rational.html
//! [sys]:       https://tspiteri.gitlab.io/rug/gmp_mpfr_sys/index.html

#![warn(missing_docs)]
#![doc(html_root_url = "https://tspiteri.gitlab.io/rug/",
       test(attr(deny(warnings))))]

extern crate gmp_mpfr_sys;

#[macro_use]
mod macros;
mod inner;

pub mod ops;
pub mod rand;

pub mod integer;
#[cfg(feature = "rational")]
pub mod rational;
#[cfg(feature = "float")]
pub mod float;
#[cfg(feature = "complex")]
pub mod complex;

#[cfg(feature = "complex")]
pub use complex::Complex;
#[cfg(feature = "float")]
pub use float::Float;
pub use integer::Integer;
pub use ops::{Assign, AssignRound, FromRound};
#[cfg(feature = "rational")]
pub use rational::Rational;