[−][src]Struct ramp::rational::Rational
An arbitrary-precision rational number.
This type is used to represent numbers in the form a / b
where a
and b
are Int
s and b
is non-zero.
Implementations
impl Rational
[src]
pub fn abs(self) -> Rational
[src]
Consumes this Rational
, returning its absolute value.
pub fn new(n: Int, d: Int) -> Rational
[src]
Creates a new Rational
from a numerator n
and denominator d
.
This method normalizes the Rational
.
Panics
Panics if d
is zero.
pub fn into_parts(self) -> (Int, Int)
[src]
Returns the (numerator, denominator) of this Rational
in normalized form.
pub fn normalized(&self) -> bool
[src]
Returns whether or not this Rational
is normalized.
pub fn normalize(&mut self)
[src]
Normalize this Rational
in place.
This method ensures that the Rational
is represented in lowest forms, i.e. as a/b
such
that a
and b
share no common factors. It also ensures that the denominator is positive.
Normalizing rationals results in faster calculations, ensuring that the numerator and denominator are as small as possible.
Most of the time, this method is called automatically.
pub fn invert(self) -> Rational
[src]
Consumes this Rational
, returning its reciprocal.
Panics
Panics if the Rational
is zero. This can be checked with the is_zero method.
pub fn round(self) -> Int
[src]
Consumes this Rational
, rounding it to the nearest Int
.
This method will round half values away from zero, similarly to f64::round
.
pub fn sign(&self) -> i32
[src]
Returns the sign of this Rational
as either -1, 0 or 1 depending on whether it is
negative, zero, or positive, respectively.
pub fn to_f64(&self) -> f64
[src]
Converts this Rational
into an f64
.
This is not an exact conversion, because this Rational
may be more precise than an f64
can account for.
Currently, this conversion is naïve, simply converting the numerator and denominator into
f64
s and dividing them.
Trait Implementations
impl<'a> Add<&'a Int> for Rational
[src]
type Output = Rational
The resulting type after applying the +
operator.
fn add(self, other: &'a Int) -> Rational
[src]
impl<'a, 'b> Add<&'a Int> for &'b Rational
[src]
type Output = Rational
The resulting type after applying the +
operator.
fn add(self, other: &'a Int) -> Rational
[src]
impl<'a> Add<&'a Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the +
operator.
fn add(self, other: &'a Rational) -> Rational
[src]
impl<'a, 'b> Add<&'a Rational> for &'b Rational
[src]
type Output = Rational
The resulting type after applying the +
operator.
fn add(self, other: &'a Rational) -> Rational
[src]
impl<'a> Add<&'a Rational> for Int
[src]
type Output = Rational
The resulting type after applying the +
operator.
fn add(self, other: &'a Rational) -> Rational
[src]
impl<'a, 'b> Add<&'a Rational> for &'b Int
[src]
type Output = Rational
The resulting type after applying the +
operator.
fn add(self, other: &'a Rational) -> Rational
[src]
impl Add<Int> for Rational
[src]
type Output = Rational
The resulting type after applying the +
operator.
fn add(self, other: Int) -> Rational
[src]
impl<'a> Add<Int> for &'a Rational
[src]
type Output = Rational
The resulting type after applying the +
operator.
fn add(self, other: Int) -> Rational
[src]
impl Add<Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the +
operator.
fn add(self, other: Rational) -> Rational
[src]
impl<'a> Add<Rational> for &'a Rational
[src]
type Output = Rational
The resulting type after applying the +
operator.
fn add(self, other: Rational) -> Rational
[src]
impl Add<Rational> for Int
[src]
type Output = Rational
The resulting type after applying the +
operator.
fn add(self, other: Rational) -> Rational
[src]
impl<'a> Add<Rational> for &'a Int
[src]
type Output = Rational
The resulting type after applying the +
operator.
fn add(self, other: Rational) -> Rational
[src]
impl<'a> AddAssign<&'a Int> for Rational
[src]
fn add_assign(&mut self, other: &'a Int)
[src]
impl<'a> AddAssign<&'a Rational> for Rational
[src]
fn add_assign(&mut self, other: &'a Rational)
[src]
impl AddAssign<Int> for Rational
[src]
fn add_assign(&mut self, other: Int)
[src]
impl AddAssign<Rational> for Rational
[src]
fn add_assign(&mut self, other: Rational)
[src]
impl Clone for Rational
[src]
impl Debug for Rational
[src]
impl Default for Rational
[src]
impl Display for Rational
[src]
impl<'a> Div<&'a Int> for Rational
[src]
type Output = Rational
The resulting type after applying the /
operator.
fn div(self, other: &'a Int) -> Rational
[src]
impl<'a, 'b> Div<&'a Int> for &'b Rational
[src]
type Output = Rational
The resulting type after applying the /
operator.
fn div(self, other: &'a Int) -> Rational
[src]
impl<'a> Div<&'a Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the /
operator.
fn div(self, other: &'a Rational) -> Rational
[src]
impl<'a, 'b> Div<&'a Rational> for &'b Rational
[src]
type Output = Rational
The resulting type after applying the /
operator.
fn div(self, other: &'a Rational) -> Rational
[src]
impl<'a> Div<&'a Rational> for Int
[src]
type Output = Rational
The resulting type after applying the /
operator.
fn div(self, other: &'a Rational) -> Rational
[src]
impl<'a, 'b> Div<&'a Rational> for &'b Int
[src]
type Output = Rational
The resulting type after applying the /
operator.
fn div(self, other: &'a Rational) -> Rational
[src]
impl Div<Int> for Rational
[src]
type Output = Rational
The resulting type after applying the /
operator.
fn div(self, other: Int) -> Rational
[src]
impl<'a> Div<Int> for &'a Rational
[src]
type Output = Rational
The resulting type after applying the /
operator.
fn div(self, other: Int) -> Rational
[src]
impl Div<Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the /
operator.
fn div(self, other: Rational) -> Rational
[src]
impl<'a> Div<Rational> for &'a Rational
[src]
type Output = Rational
The resulting type after applying the /
operator.
fn div(self, other: Rational) -> Rational
[src]
impl Div<Rational> for Int
[src]
type Output = Rational
The resulting type after applying the /
operator.
fn div(self, other: Rational) -> Rational
[src]
impl<'a> Div<Rational> for &'a Int
[src]
type Output = Rational
The resulting type after applying the /
operator.
fn div(self, other: Rational) -> Rational
[src]
impl<'a> DivAssign<&'a Int> for Rational
[src]
fn div_assign(&mut self, other: &'a Int)
[src]
impl<'a> DivAssign<&'a Rational> for Rational
[src]
fn div_assign(&mut self, other: &'a Rational)
[src]
impl DivAssign<Int> for Rational
[src]
fn div_assign(&mut self, other: Int)
[src]
impl DivAssign<Rational> for Rational
[src]
fn div_assign(&mut self, other: Rational)
[src]
impl Eq for Rational
[src]
impl<U: Into<Int>> From<U> for Rational
[src]
impl From<f32> for Rational
[src]
impl From<f64> for Rational
[src]
impl FromStr for Rational
[src]
type Err = ParseRationalError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Rational, ParseRationalError>
[src]
impl Hash for Rational
[src]
fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a> Mul<&'a Int> for Rational
[src]
type Output = Rational
The resulting type after applying the *
operator.
fn mul(self, other: &'a Int) -> Rational
[src]
impl<'a, 'b> Mul<&'a Int> for &'b Rational
[src]
type Output = Rational
The resulting type after applying the *
operator.
fn mul(self, other: &'a Int) -> Rational
[src]
impl<'a> Mul<&'a Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the *
operator.
fn mul(self, other: &'a Rational) -> Rational
[src]
impl<'a, 'b> Mul<&'a Rational> for &'b Rational
[src]
type Output = Rational
The resulting type after applying the *
operator.
fn mul(self, other: &'a Rational) -> Rational
[src]
impl<'a> Mul<&'a Rational> for Int
[src]
type Output = Rational
The resulting type after applying the *
operator.
fn mul(self, other: &'a Rational) -> Rational
[src]
impl<'a, 'b> Mul<&'a Rational> for &'b Int
[src]
type Output = Rational
The resulting type after applying the *
operator.
fn mul(self, other: &'a Rational) -> Rational
[src]
impl Mul<Int> for Rational
[src]
type Output = Rational
The resulting type after applying the *
operator.
fn mul(self, other: Int) -> Rational
[src]
impl<'a> Mul<Int> for &'a Rational
[src]
type Output = Rational
The resulting type after applying the *
operator.
fn mul(self, other: Int) -> Rational
[src]
impl Mul<Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the *
operator.
fn mul(self, other: Rational) -> Rational
[src]
impl<'a> Mul<Rational> for &'a Rational
[src]
type Output = Rational
The resulting type after applying the *
operator.
fn mul(self, other: Rational) -> Rational
[src]
impl Mul<Rational> for Int
[src]
type Output = Rational
The resulting type after applying the *
operator.
fn mul(self, other: Rational) -> Rational
[src]
impl<'a> Mul<Rational> for &'a Int
[src]
type Output = Rational
The resulting type after applying the *
operator.
fn mul(self, other: Rational) -> Rational
[src]
impl<'a> MulAssign<&'a Int> for Rational
[src]
fn mul_assign(&mut self, other: &'a Int)
[src]
impl<'a> MulAssign<&'a Rational> for Rational
[src]
fn mul_assign(&mut self, other: &'a Rational)
[src]
impl MulAssign<Int> for Rational
[src]
fn mul_assign(&mut self, other: Int)
[src]
impl MulAssign<Rational> for Rational
[src]
fn mul_assign(&mut self, other: Rational)
[src]
impl Neg for Rational
[src]
type Output = Rational
The resulting type after applying the -
operator.
fn neg(self) -> Rational
[src]
impl<'a> Neg for &'a Rational
[src]
type Output = Rational
The resulting type after applying the -
operator.
fn neg(self) -> Rational
[src]
impl One for Rational
[src]
fn one() -> Rational
[src]
fn set_one(&mut self)
[src]
fn is_one(&self) -> bool where
Self: PartialEq<Self>,
[src]
Self: PartialEq<Self>,
impl Ord for Rational
[src]
fn cmp(&self, other: &Rational) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Int> for Rational
[src]
impl PartialEq<Rational> for Rational
[src]
impl PartialEq<Rational> for Int
[src]
impl PartialOrd<Int> for Rational
[src]
fn partial_cmp(&self, other: &Int) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Rational> for Rational
[src]
fn partial_cmp(&self, other: &Rational) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Rational> for Int
[src]
fn partial_cmp(&self, other: &Rational) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> Sub<&'a Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the -
operator.
fn sub(self, other: &'a Rational) -> Rational
[src]
impl<'a, 'b> Sub<&'a Rational> for &'b Rational
[src]
type Output = Rational
The resulting type after applying the -
operator.
fn sub(self, other: &'a Rational) -> Rational
[src]
impl Sub<Rational> for Rational
[src]
type Output = Rational
The resulting type after applying the -
operator.
fn sub(self, other: Rational) -> Rational
[src]
impl<'a> Sub<Rational> for &'a Rational
[src]
type Output = Rational
The resulting type after applying the -
operator.
fn sub(self, other: Rational) -> Rational
[src]
impl<'a> SubAssign<&'a Rational> for Rational
[src]
fn sub_assign(&mut self, other: &'a Rational)
[src]
impl SubAssign<Rational> for Rational
[src]
fn sub_assign(&mut self, other: Rational)
[src]
impl Zero for Rational
[src]
Auto Trait Implementations
impl RefUnwindSafe for Rational
impl Send for Rational
impl Sync for Rational
impl Unpin for Rational
impl UnwindSafe for Rational
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,