Arbitrary-precision numbers
The rug crate provides integers and floating-point numbers with
arbitrary precision and correct rounding. Its main features are:
- big integers with arbitrary precision,
- big rational numbers with arbitrary precision,
- multi-precision floating-point numbers with correct rounding, and
- multi-precision complex numbers 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 and GNU GPL for details.
Basic use
Documentation for this crate is available. This crate depends
on the low-level bindings in the gmp-mpfr-sys crate, which
provides RUST FFI bindings for:
- the GNU Multiple Precision Arithmetic Library (GMP),
- the GNU MPFR Library, a library for multiple-precision floating-point computations, and
- GNU MPC, a library for the arithmetic of complex numbers with arbitrarily high precision.
It can be helpful to refer to the documentation of the GMP, MPFR and MPC libraries.
Examples
extern crate rug;
use ;
Usage
To use rug in your crate, add extern crate rug; to the crate root
and add rug as a dependency in Cargo.toml:
[]
= "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 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:
[]
= "0.4.0"
= false
To use features selectively, you can add this to Cargo.toml:
[]
= "0.4.0"
= false
# Pick which features to use
= ["rational", "float"]
Note that the the complex feature will enable the float feature,
on which it depends.