Arbitrary-precision integers
The rugint crate provides arbitrary-precision integers using the
GNU Multiple Precision Arithmetic Library
(GMP). It is one of a group of four crates:
rugintfor arbitrary-precision integers,rugratfor arbitrary-precision rational numbers,rugflofor multiple-precision floating-point numbers, andrugcomfor multiple-precision complex numbers.
Documentation
Documentation for this crate is available.
It can also be helpful to refer to the documentation at the GMP page.
The crate provides the
Integer
type, which holds an arbitrary-precision integer. You can construct
this from primitive data types, and use the standard arithmetic
operators. Many operators can also operate on a mixture of this type
and primitive types; in this case, the result is returned as an
arbitrary-precision type.
Examples
extern crate rugint;
use ;
Arithmetic operations with mixed arbitrary and primitive types are allowed. However, the supported operations are not exhaustive.
use Integer;
let mut a = from;
a = + 0xffee;
assert!;
// ^ ^ ^ ^ ^
// 80 64 48 32 16
Note that in the above example, there is only one construction.
The Integer instance is moved into the shift operation so that
the result can be stored in the same instance, then that result is
similarly consumed by the addition operation.
Usage
To use this crate, add rugint as a dependency in Cargo.toml:
[]
= "0.1"
This crate depends on the low-level bindings in the crate
gmp-mpfr-sys. This
should be transparent on GNU/Linux and macOS, but may need some work
on Windows. See the gmp-mpfr-sys
README
for some details.
License
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 LICENSE-LGPL and LICENSE-GPL for details.