Struct gmp_mpfr::Rational [] [src]

pub struct Rational { /* fields omitted */ }

An arbitrary-precision rational number.

A rational number is made up of a numerator Integer and denominator Integer. After rational number functions, the number is always in canonical form, that is, the denominator is always greater than zero, and there are no common factors. Zero is stored as 0/1.

Examples

use gmp_mpfr::{Integer, Rational};

let r = Rational::from((-12, 15));
let (num, den) = r.into_numer_denom();
assert!(num == -4);
assert!(den == 5);
let one = Rational::from((num, Integer::from(-4)));
assert!(one == 1);

Methods

impl Rational
[src]

Constructs a new arbitrary-precision rational number with value 0.

Converts self to an f64, rounding towards zero.

Converts self to an f32, rounding towards zero.

Borrows the numerator.

Borrows the denominator.

Borrows the numerator and denominator.

Borrows the numerator and denominator mutably. The number is canonicalized when the borrow ends. The denominator must not be zero when the borrow ends.

Examples

use gmp_mpfr::Rational;

let mut r = Rational::from((3, 5));
{
    let mut num_den = r.as_mut_numer_denom();
    // change r from 3/5 to 4/8, which is equal to 1/2
    *num_den.0 += 1;
    *num_den.1 += 3;
    // borrow ends here
}
let num_den = r.as_numer_denom();
assert!(*num_den.0 == 1 && *num_den.1 == 2);

Panics

Panics if the denominator is zero when the borrow ends.

Converts self into numerator and denominator integers, consuming self.

Computes the absolute value of self

Computes the reciprocal of self.

Returns Less if self is less than zero, Greater if self is greater than zero, or Equal if self is equal to zero.

Returns a string representation of self for the specified radix. If radix is > 36, 'a' to 'z' represent digits 10 to 36, and 'A' to 'Z' represent digits 37 to 62. The exponent is encoded in decimal.

Panics

Panics if radix is less than 2 or greater than 62.

Trait Implementations

impl<'a> From<&'a Float> for Rational
[src]

Constructs a Rational from a Float, preserving all the precision of the value. The value must not be a NaN or infinite.

Examples

use gmp_mpfr::{Float, FromPrec, Rational};

let large_f = Float::from_prec(6.5, 16);
let large_r = Rational::from(&large_f); // borrow
let small_f = Float::from_prec(-0.125, 16);
let small_r = Rational::from(small_f); // move

assert!(*large_r.numer() == 13);
assert!(*large_r.denom() == 2);
assert!(*small_r.numer() == -1);
assert!(*small_r.denom() == 8);

Panics

Panics if val is a NaN or infinite.

impl From<Float> for Rational
[src]

Constructs a Rational from a Float, preserving all the precision of the value. The value must not be a NaN or infinite. See the borrowing implementor.

Panics

Panics if val is a NaN or infinite.

impl<'a> Assign<&'a Float> for Rational
[src]

Assigns from a Float, preserving all the precision of the value. The value must not be a NaN or infinite.

Examples

use gmp_mpfr::{Assign, Float, FromPrec, Rational};

let large_f = Float::from_prec(6.5, 16);
let mut large_r = Rational::new();
large_r.assign(&large_f); // borrow
let small_f = Float::from_prec(-0.125, 16);
let mut small_r = Rational::new();
small_r.assign(small_f); // move

assert!(*large_r.numer() == 13);
assert!(*large_r.denom() == 2);
assert!(*small_r.numer() == -1);
assert!(*small_r.denom() == 8);

Panics

Panics if val is a NaN or infinite.

impl<'a> Assign<Float> for Rational
[src]

Assigns from a Float, preserving all the precision of the value. The value must not be a NaN or infinite. See the borrowing implementor.

Panics

Panics if val is a NaN or infinite.

impl Add<Float> for Rational
[src]

The resulting type after applying the + operator

The method for the + operator

impl<'a> Add<&'a Float> for Rational
[src]

The resulting type after applying the + operator

The method for the + operator

impl AddRound<Float> for Rational
[src]

The resulting type after the addition.

Performs the addition.

impl<'a> AddRound<&'a Float> for Rational
[src]

The resulting type after the addition.

Performs the addition.

impl Mul<Float> for Rational
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> Mul<&'a Float> for Rational
[src]

The resulting type after applying the * operator

The method for the * operator

impl MulRound<Float> for Rational
[src]

The resulting type after the multiplication.

Performs the multiplication.

impl<'a> MulRound<&'a Float> for Rational
[src]

The resulting type after the multiplication.

Performs the multiplication.

impl PartialEq<Float> for Rational
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialOrd<Float> for Rational
[src]

Returns the ordering of self and other, or None if other is a NaN.

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Drop for Rational
[src]

A method called when the value goes out of scope. Read more

impl Default for Rational
[src]

Returns the "default value" for a type. Read more

impl Clone for Rational
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a> From<&'a Rational> for Rational
[src]

Constructs a Rational from another Rational.

impl From<Integer> for Rational
[src]

Constructs a Rational from an Integer. This constructor allocates one Integer for the denominator and reuses val for the numerator.

impl<'a> From<&'a Integer> for Rational
[src]

Constructs a Rational from an Integer.

impl From<(Integer, Integer)> for Rational
[src]

Constructs a Rational from a numerator Integer and denominator Integer. This constructor does not allocate, as it reuses the Integer components.

Panics

Panics if the denominator is zero.

impl<'a> From<(&'a Integer, &'a Integer)> for Rational
[src]

Constructs a Rational from a numerator Integer and denominator Integer.

impl From<u32> for Rational
[src]

Constructs a Rational from a u32.

impl From<i32> for Rational
[src]

Constructs a Rational from an i32.

impl From<f64> for Rational
[src]

Constructs a Rational from an f64, losing no precision.

Panics

Panics if t is a NaN or infinite.

impl From<f32> for Rational
[src]

Constructs a Rational from an f32, losing no precision.

Panics

Panics if t is a NaN or infinite.

impl From<(u32, u32)> for Rational
[src]

Constructs a Rational from a numerator u32 and denominator u32.

impl From<(i32, u32)> for Rational
[src]

Constructs a Rational from a numerator i32 and denominator u32.

impl From<(i32, i32)> for Rational
[src]

Constructs a Rational from a numerator i32 and denominator i32.

impl<'a> Assign<&'a Rational> for Rational
[src]

Assigns from another Rational.

impl Assign<Rational> for Rational
[src]

Assigns from another Rational.

impl<'a> Assign<&'a Integer> for Rational
[src]

Assigns from an Integer.

impl Assign<Integer> for Rational
[src]

Assigns from an Integer.

impl Assign<(Integer, Integer)> for Rational
[src]

Assigns from a numerator Integer and a denominator Integer.

Panics

Panics if the denominator is zero.

impl<'a> Assign<(&'a Integer, &'a Integer)> for Rational
[src]

Assigns from a numerator Integer and a denominator Integer.

Panics

Panics if the denominator is zero.

impl Assign<u32> for Rational
[src]

Assigns from a u32.

impl Assign<i32> for Rational
[src]

Assigns from an i32.

impl Assign<f64> for Rational
[src]

Assigns from an f64, losing no precision.

Panics

Panics if f is a NaN or infinite.

impl Assign<f32> for Rational
[src]

Assigns from an f32, losing no precision.

Panics

Panics if f is a NaN or infinite.

impl Assign<(u32, u32)> for Rational
[src]

Assigns from a numerator u32 and a denominator u32.

Panics

Panics if the denominator is zero.

impl Assign<(i32, u32)> for Rational
[src]

Assigns from a numerator i32 and a denominator u32.

Panics

Panics if the denominator is zero.

impl Assign<(i32, i32)> for Rational
[src]

Assigns from a numerator i32 and a denominator i32.

Panics

Panics if the denominator is zero.

impl<'a> Add<&'a Rational> for Rational
[src]

The resulting type after applying the + operator

The method for the + operator

impl Add<Rational> for Rational
[src]

The resulting type after applying the + operator

The method for the + operator

impl<'a> AddAssign<&'a Rational> for Rational
[src]

The method for the += operator

impl AddAssign<Rational> for Rational
[src]

The method for the += operator

impl<'a> Sub<&'a Rational> for Rational
[src]

The resulting type after applying the - operator

The method for the - operator

impl Sub<Rational> for Rational
[src]

The resulting type after applying the - operator

The method for the - operator

impl<'a> SubAssign<&'a Rational> for Rational
[src]

The method for the -= operator

impl SubAssign<Rational> for Rational
[src]

The method for the -= operator

impl<'a> Mul<&'a Rational> for Rational
[src]

The resulting type after applying the * operator

The method for the * operator

impl Mul<Rational> for Rational
[src]

The resulting type after applying the * operator

The method for the * operator

impl<'a> MulAssign<&'a Rational> for Rational
[src]

The method for the *= operator

impl MulAssign<Rational> for Rational
[src]

The method for the *= operator

impl<'a> Div<&'a Rational> for Rational
[src]

The resulting type after applying the / operator

The method for the / operator

impl Div<Rational> for Rational
[src]

The resulting type after applying the / operator

The method for the / operator

impl<'a> DivAssign<&'a Rational> for Rational
[src]

The method for the /= operator

impl DivAssign<Rational> for Rational
[src]

The method for the /= operator

impl SubFromAssign for Rational
[src]

Peforms the subtraction.

impl<'a> SubFromAssign<&'a Rational> for Rational
[src]

Peforms the subtraction.

impl DivFromAssign for Rational
[src]

Peforms the division.

impl<'a> DivFromAssign<&'a Rational> for Rational
[src]

Peforms the division.

impl Shl<u32> for Rational
[src]

The resulting type after applying the << operator

Multiplies self by 2 to the power of op.

impl ShlAssign<u32> for Rational
[src]

Multiplies self by 2 to the power of op.

impl Shr<u32> for Rational
[src]

The resulting type after applying the >> operator

Divides self by 2 to the power of op.

impl ShrAssign<u32> for Rational
[src]

Divides self by 2 to the power of op.

impl Pow<i32> for Rational
[src]

The resulting type after the power operation.

Performs the power operation.

impl PowAssign<i32> for Rational
[src]

Peforms the power operation.

impl Neg for Rational
[src]

The resulting type after applying the - operator

The method for the unary - operator

impl NegAssign for Rational
[src]

Peforms the negation.

impl Eq for Rational
[src]

impl Ord for Rational
[src]

This method returns an Ordering between self and other. Read more

impl PartialEq for Rational
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialOrd for Rational
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialEq<Integer> for Rational
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialOrd<Integer> for Rational
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialEq<u32> for Rational
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialOrd<u32> for Rational
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialEq<i32> for Rational
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialOrd<i32> for Rational
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialEq<(u32, u32)> for Rational
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialOrd<(u32, u32)> for Rational
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialEq<(i32, u32)> for Rational
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialOrd<(i32, u32)> for Rational
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialEq<(i32, i32)> for Rational
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialOrd<(i32, i32)> for Rational
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Display for Rational
[src]

Formats the value using the given formatter.

impl Debug for Rational
[src]

Formats the value using the given formatter.

impl Binary for Rational
[src]

Formats the value using the given formatter.

impl Octal for Rational
[src]

Formats the value using the given formatter.

impl LowerHex for Rational
[src]

Formats the value using the given formatter.

impl UpperHex for Rational
[src]

Formats the value using the given formatter.