pub trait Rational: Number {
// Required methods
fn is_integer(&self) -> bool;
fn is_proper(&self) -> bool;
fn is_reduced(&self) -> bool;
fn reduce(&mut self);
fn reduced(&self) -> Self;
fn invert(&mut self);
fn inverted(&self) -> Self;
// Provided methods
fn is_improper(&self) -> bool { ... }
fn is_reducible(&self) -> bool { ... }
fn invert_reduce(&mut self) { ... }
fn inverted_reduced(&self) -> Self
where Self: Sized { ... }
}Expand description
Common trait for all rationals.
Required Methods§
Sourcefn is_integer(&self) -> bool
fn is_integer(&self) -> bool
Is fraction an integer?
Retuns true if the denominator 1 or the numerator is a multiple of the
denominator.
Sourcefn is_proper(&self) -> bool
fn is_proper(&self) -> bool
Is this a proper fraction (m) such that $a/b<1$?
Retuns true if the numerator is smaller than the denominator.
Sourcefn is_reduced(&self) -> bool
fn is_reduced(&self) -> bool
Is this a reduced fraction (m).
Returns true if the numerator and denominator have no common factors
other than 1.
Sourcefn reduce(&mut self)
fn reduce(&mut self)
Reduces the fraction in place to its simplest form by dividing both the numerator and denominator by their greatest common divisor (GCD).
Sourcefn reduced(&self) -> Self
fn reduced(&self) -> Self
Returns the reduced fraction to its simplest form by dividing both the numerator and denominator by their greatest common divisor (GCD).
Provided Methods§
Sourcefn is_improper(&self) -> bool
fn is_improper(&self) -> bool
Is this an improper fraction (m) such that $a/b>1$?
Retuns true if the numerator is greater than the denominator.
E.g.: $ \dfrac{48}{23} , \dfrac{3}{2} … $
Sourcefn is_reducible(&self) -> bool
fn is_reducible(&self) -> bool
Is this fraction not in its reduced mode (m)?
Returns true if the numerator and denominator share a common factor
greater than 1, indicating that the fraction can be reduced further.
Sourcefn invert_reduce(&mut self)
fn invert_reduce(&mut self)
Inverts and reduces the fraction.
Sourcefn inverted_reduced(&self) -> Selfwhere
Self: Sized,
fn inverted_reduced(&self) -> Selfwhere
Self: Sized,
Returns the inverted and reduced fraction.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.