Crate rugrat [] [src]

Arbitrary-precision rational numbers

The rugrat crate provides arbitrary-precision rational numbers 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.

See the LGPL and GPL for details.

This crate is one of a group of four crates:

  • rugint provides arbitrary-precision integers based on GMP.
  • rugrat provides arbitrary-precision rational number based on GMP.
  • rugflo provides arbitrary-precision floating-point numbers based on MPFR.
  • rugcom provides arbitrary-precision complex numbers based on MPC.

Basic use

The crate provides the Rational type, which holds an arbitrary-precision rational number.

Examples

use rugrat::Rational;
// Create a rational number, -22 / 4 = -11 / 2.
let rat = Rational::from((-22, 4));
assert!(*rat.numer() == -11);
assert!(*rat.denom() == 2);
assert!(rat.to_f32() == -5.5);

Usage

To use rugrat in your crate, add extern crate rugrat; to the crate root and add rugrat as a dependency in Cargo.toml:

[dependencies]
rugrat = "0.2.0"

The rugrat 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 gmp-mpfr-sys for some details.

Structs

MutNumerDenom

Used to borrow the numerator and denominator of a Rational number mutably.

ParseRationalError
Rational

An arbitrary-precision rational number.