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.
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, andrugcom
for multiple-precision complex numbers.
Basic use
The crate provides the Rational
type,
which holds an arbitrary-precision rational number.
Examples
extern crate rugint; extern crate rugrat; use rugint::Assign; use rugrat::Rational; fn main() { // Create a rational number, -22 / 4 = -11 / 2. let rat = Rational::from((-22, 4)); assert!(rat.numer().to_i32() == -11); assert!(*rat.denom() == 2); assert!(rat.to_f32() == -5.5); }
Structs
MutNumerDenom |
Used to borrow the numerator and denominator of a
|
Rational |
An arbitrary-precision rational number. |