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]
fn new() -> Rational
Constructs a new arbitrary-precision rational number with value 0.
fn to_f64(&self) -> f64
Converts self
to an f64
, rounding towards zero.
fn to_f32(&self) -> f32
Converts self
to an f32
, rounding towards zero.
fn numer(&self) -> &Integer
Borrows the numerator.
fn denom(&self) -> &Integer
Borrows the denominator.
fn as_numer_denom(&self) -> (&Integer, &Integer)
Borrows the numerator and denominator.
fn as_mut_numer_denom(&mut self) -> MutNumerDenom
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.
fn into_numer_denom(self) -> (Integer, Integer)
Converts self
into numerator and denominator integers,
consuming self
.
fn abs(&mut self) -> &mut Rational
Computes the absolute value of self
fn recip(&mut self) -> &mut Rational
Computes the reciprocal of self
.
fn sign(&self) -> Ordering
Returns Less
if self
is less than zero,
Greater
if self
is greater than zero,
or Equal
if self
is equal to zero.
fn to_string_radix(&self, radix: i32) -> String
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]
fn from(val: &Float) -> Rational
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]
fn from(val: Float) -> Rational
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]
fn assign(&mut self, val: &'a Float)
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]
fn assign(&mut self, val: Float)
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]
type Output = Float
The resulting type after applying the +
operator
fn add(self, op: Float) -> Float
The method for the +
operator
impl<'a> Add<&'a Float> for Rational
[src]
type Output = Float
The resulting type after applying the +
operator
fn add(self, op: &'a Float) -> Float
The method for the +
operator
impl AddRound<Float> for Rational
[src]
type Output = Float
The resulting type after the addition.
fn add_round(self, op: Float, round: Round) -> (Float, Ordering)
Performs the addition.
impl<'a> AddRound<&'a Float> for Rational
[src]
type Output = Float
The resulting type after the addition.
fn add_round(self, op: &'a Float, round: Round) -> (Float, Ordering)
Performs the addition.
impl Mul<Float> for Rational
[src]
type Output = Float
The resulting type after applying the *
operator
fn mul(self, op: Float) -> Float
The method for the *
operator
impl<'a> Mul<&'a Float> for Rational
[src]
type Output = Float
The resulting type after applying the *
operator
fn mul(self, op: &'a Float) -> Float
The method for the *
operator
impl MulRound<Float> for Rational
[src]
type Output = Float
The resulting type after the multiplication.
fn mul_round(self, op: Float, round: Round) -> (Float, Ordering)
Performs the multiplication.
impl<'a> MulRound<&'a Float> for Rational
[src]
type Output = Float
The resulting type after the multiplication.
fn mul_round(self, op: &'a Float, round: Round) -> (Float, Ordering)
Performs the multiplication.
impl PartialEq<Float> for Rational
[src]
fn eq(&self, other: &Float) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl PartialOrd<Float> for Rational
[src]
fn partial_cmp(&self, other: &Float) -> Option<Ordering>
Returns the ordering of self
and other
, or None
if other
is a NaN.
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
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]
impl Default for Rational
[src]
impl Clone for Rational
[src]
fn clone(&self) -> Rational
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Rational)
Performs copy-assignment from source
. Read more
impl<'a> From<&'a Rational> for Rational
[src]
impl From<Integer> for Rational
[src]
fn from(val: Integer) -> Rational
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]
impl From<(Integer, Integer)> for Rational
[src]
fn from((num, den): (Integer, Integer)) -> Rational
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]
fn from(t: (&'a Integer, &'a Integer)) -> Rational
Constructs a Rational
from
a numerator Integer
and denominator Integer
.
impl From<u32> for Rational
[src]
impl From<i32> for Rational
[src]
impl From<f64> for Rational
[src]
impl From<f32> for Rational
[src]
impl From<(u32, u32)> for Rational
[src]
impl From<(i32, u32)> for Rational
[src]
impl From<(i32, i32)> for Rational
[src]
impl<'a> Assign<&'a Rational> for Rational
[src]
impl Assign<Rational> for Rational
[src]
impl<'a> Assign<&'a Integer> for Rational
[src]
impl Assign<Integer> for Rational
[src]
impl Assign<(Integer, Integer)> for Rational
[src]
fn assign(&mut self, (num, den): (Integer, Integer))
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]
fn assign(&mut self, (num, den): (&Integer, &Integer))
Assigns from a numerator Integer
and a denominator Integer
.
Panics
Panics if the denominator is zero.
impl Assign<u32> for Rational
[src]
impl Assign<i32> for Rational
[src]
impl Assign<f64> for Rational
[src]
impl Assign<f32> for Rational
[src]
impl Assign<(u32, u32)> for Rational
[src]
impl Assign<(i32, u32)> for Rational
[src]
impl Assign<(i32, i32)> for Rational
[src]
impl<'a> Add<&'a Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the +
operator
fn add(self, op: &'a Rational) -> Rational
The method for the +
operator
impl Add<Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the +
operator
fn add(self, op: Rational) -> Rational
The method for the +
operator
impl<'a> AddAssign<&'a Rational> for Rational
[src]
fn add_assign(&mut self, op: &'a Rational)
The method for the +=
operator
impl AddAssign<Rational> for Rational
[src]
fn add_assign(&mut self, op: Rational)
The method for the +=
operator
impl<'a> Sub<&'a Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the -
operator
fn sub(self, op: &'a Rational) -> Rational
The method for the -
operator
impl Sub<Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the -
operator
fn sub(self, op: Rational) -> Rational
The method for the -
operator
impl<'a> SubAssign<&'a Rational> for Rational
[src]
fn sub_assign(&mut self, op: &'a Rational)
The method for the -=
operator
impl SubAssign<Rational> for Rational
[src]
fn sub_assign(&mut self, op: Rational)
The method for the -=
operator
impl<'a> Mul<&'a Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the *
operator
fn mul(self, op: &'a Rational) -> Rational
The method for the *
operator
impl Mul<Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the *
operator
fn mul(self, op: Rational) -> Rational
The method for the *
operator
impl<'a> MulAssign<&'a Rational> for Rational
[src]
fn mul_assign(&mut self, op: &'a Rational)
The method for the *=
operator
impl MulAssign<Rational> for Rational
[src]
fn mul_assign(&mut self, op: Rational)
The method for the *=
operator
impl<'a> Div<&'a Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the /
operator
fn div(self, op: &'a Rational) -> Rational
The method for the /
operator
impl Div<Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the /
operator
fn div(self, op: Rational) -> Rational
The method for the /
operator
impl<'a> DivAssign<&'a Rational> for Rational
[src]
fn div_assign(&mut self, op: &'a Rational)
The method for the /=
operator
impl DivAssign<Rational> for Rational
[src]
fn div_assign(&mut self, op: Rational)
The method for the /=
operator
impl SubFromAssign for Rational
[src]
fn sub_from_assign(&mut self, lhs: Rational)
Peforms the subtraction.
impl<'a> SubFromAssign<&'a Rational> for Rational
[src]
fn sub_from_assign(&mut self, lhs: &Rational)
Peforms the subtraction.
impl DivFromAssign for Rational
[src]
fn div_from_assign(&mut self, lhs: Rational)
Peforms the division.
impl<'a> DivFromAssign<&'a Rational> for Rational
[src]
fn div_from_assign(&mut self, lhs: &Rational)
Peforms the division.
impl Shl<u32> for Rational
[src]
type Output = Rational
The resulting type after applying the <<
operator
fn shl(self, op: u32) -> Rational
Multiplies self
by 2 to the power of op
.
impl ShlAssign<u32> for Rational
[src]
fn shl_assign(&mut self, op: u32)
Multiplies self
by 2 to the power of op
.
impl Shr<u32> for Rational
[src]
type Output = Rational
The resulting type after applying the >>
operator
fn shr(self, op: u32) -> Rational
Divides self
by 2 to the power of op
.
impl ShrAssign<u32> for Rational
[src]
fn shr_assign(&mut self, op: u32)
Divides self
by 2 to the power of op
.
impl Pow<i32> for Rational
[src]
type Output = Rational
The resulting type after the power operation.
fn pow(self, op: i32) -> Rational
Performs the power operation.
impl PowAssign<i32> for Rational
[src]
fn pow_assign(&mut self, op: i32)
Peforms the power operation.
impl Neg for Rational
[src]
type Output = Rational
The resulting type after applying the -
operator
fn neg(self) -> Rational
The method for the unary -
operator
impl NegAssign for Rational
[src]
fn neg_assign(&mut self)
Peforms the negation.
impl Eq for Rational
[src]
impl Ord for Rational
[src]
fn cmp(&self, other: &Rational) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl PartialEq for Rational
[src]
fn eq(&self, other: &Rational) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl PartialOrd for Rational
[src]
fn partial_cmp(&self, other: &Rational) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
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]
fn eq(&self, other: &Integer) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl PartialOrd<Integer> for Rational
[src]
fn partial_cmp(&self, other: &Integer) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
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]
fn eq(&self, other: &u32) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl PartialOrd<u32> for Rational
[src]
fn partial_cmp(&self, other: &u32) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
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]
fn eq(&self, other: &i32) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl PartialOrd<i32> for Rational
[src]
fn partial_cmp(&self, other: &i32) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
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]
fn eq(&self, other: &(u32, u32)) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl PartialOrd<(u32, u32)> for Rational
[src]
fn partial_cmp(&self, other: &(u32, u32)) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
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]
fn eq(&self, other: &(i32, u32)) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl PartialOrd<(i32, u32)> for Rational
[src]
fn partial_cmp(&self, other: &(i32, u32)) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
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]
fn eq(&self, other: &(i32, i32)) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl PartialOrd<(i32, i32)> for Rational
[src]
fn partial_cmp(&self, other: &(i32, i32)) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more