Crate rugint [] [src]

Arbitrary-precision integers

The rugint crate provides arbitrary-precision integers using the GNU Multiple Precision Arithmetic Library (GMP). It can be helpful to refer to the documentation at the GMP page.

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.

This crate is one of a group of four crates:

  • rugint for arbitrary-precision integers,
  • rugrat for arbitrary-precision rational numbers,
  • rugflo for multiple-precision floating-point numbers, and
  • rugcom for multiple-precision complex numbers.

Basic use

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

use rugint::{Assign, Integer};
// Create an integer initialized as zero.
let mut int = Integer::new();
assert!(int.to_u32() == 0);
assert!(int == 0);
int.assign(14);
assert!(int == 14);

Arithmetic operations with mixed arbitrary and primitive types are allowed. However, the supported operations are not exhaustive.

use rugint::Integer;
let mut a = Integer::from(0xc);
a = (a << 80) + 0xffee;
assert!(a.to_string_radix(16) == "c0000000000000000ffee");
//                                 ^   ^   ^   ^   ^
//                                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.

Structs

Integer

An arbitrary-precision integer.

Traits

Assign

Assigns to a number from another value.

DivFromAssign

Divide and assign the result to the rhs operand.

NegAssign

Negates the value inside self.

NotAssign

Peforms a bitwise complement of the value inside self.

Pow

Provides the power operation.

PowAssign

Provides the power operation inside self.

SubFromAssign

Subtract and assigns the result to the rhs operand.

Type Definitions

BitCount

The type for the bit count of an Integer value.