Struct num_rational::Ratio
[−]
[src]
pub struct Ratio<T> { // some fields omitted }
Represents the ratio between 2 numbers.
Methods
impl<T: Clone + Integer> Ratio<T>
fn from_integer(t: T) -> Ratio<T>
Creates a ratio representing the integer t
.
fn new_raw(numer: T, denom: T) -> Ratio<T>
Creates a ratio without checking for denom == 0
or reducing.
fn new(numer: T, denom: T) -> Ratio<T>
Create a new Ratio. Fails if denom == 0
.
fn to_integer(&self) -> T
Converts to an integer.
fn numer<'a>(&'a self) -> &'a T
Gets an immutable reference to the numerator.
fn denom<'a>(&'a self) -> &'a T
Gets an immutable reference to the denominator.
fn is_integer(&self) -> bool
Returns true if the rational number is an integer (denominator is 1).
fn reduced(&self) -> Ratio<T>
Returns a reduce
d copy of self.
fn recip(&self) -> Ratio<T>
Returns the reciprocal.
fn floor(&self) -> Ratio<T>
Rounds towards minus infinity.
fn ceil(&self) -> Ratio<T>
Rounds towards plus infinity.
fn round(&self) -> Ratio<T>
Rounds to the nearest integer. Rounds half-way cases away from zero.
fn trunc(&self) -> Ratio<T>
Rounds towards zero.
fn fract(&self) -> Ratio<T>
Returns the fractional part of a number.
impl<T: Clone + Integer + PrimInt> Ratio<T>
impl Ratio<BigInt>
fn from_float<T: Float>(f: T) -> Option<BigRational>
Converts a float into a rational number.
Trait Implementations
impl<T: Clone + Integer> Ord for Ratio<T>
impl<T: Clone + Integer> PartialOrd for Ratio<T>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
1.0.0fn lt(&self, other: &Rhs) -> bool
1.0.0fn le(&self, other: &Rhs) -> bool
1.0.0fn gt(&self, other: &Rhs) -> bool
1.0.0fn ge(&self, other: &Rhs) -> bool
impl<T: Clone + Integer> PartialEq for Ratio<T>
impl<T: Clone + Integer> Eq for Ratio<T>
impl<T: Clone + Integer> Mul<Ratio<T>> for Ratio<T>
impl<'a, T> Mul<Ratio<T>> for &'a Ratio<T> where T: Clone + Integer
impl<'a, T> Mul<&'a Ratio<T>> for Ratio<T> where T: Clone + Integer
impl<'a, 'b, T> Mul<&'b Ratio<T>> for &'a Ratio<T> where T: Clone + Integer
impl<T: Clone + Integer> Div<Ratio<T>> for Ratio<T>
impl<'a, T> Div<Ratio<T>> for &'a Ratio<T> where T: Clone + Integer
impl<'a, T> Div<&'a Ratio<T>> for Ratio<T> where T: Clone + Integer
impl<'a, 'b, T> Div<&'b Ratio<T>> for &'a Ratio<T> where T: Clone + Integer
impl<T: Clone + Integer> Add<Ratio<T>> for Ratio<T>
impl<'a, T> Add<Ratio<T>> for &'a Ratio<T> where T: Clone + Integer
impl<'a, T> Add<&'a Ratio<T>> for Ratio<T> where T: Clone + Integer
impl<'a, 'b, T: Clone + Integer> Add<&'b Ratio<T>> for &'a Ratio<T>
impl<T: Clone + Integer> Sub<Ratio<T>> for Ratio<T>
impl<'a, T> Sub<Ratio<T>> for &'a Ratio<T> where T: Clone + Integer
impl<'a, T> Sub<&'a Ratio<T>> for Ratio<T> where T: Clone + Integer
impl<'a, 'b, T: Clone + Integer> Sub<&'b Ratio<T>> for &'a Ratio<T>
impl<T: Clone + Integer> Rem<Ratio<T>> for Ratio<T>
impl<'a, T> Rem<Ratio<T>> for &'a Ratio<T> where T: Clone + Integer
impl<'a, T> Rem<&'a Ratio<T>> for Ratio<T> where T: Clone + Integer
impl<'a, 'b, T: Clone + Integer> Rem<&'b Ratio<T>> for &'a Ratio<T>
impl<T> Neg for Ratio<T> where T: Clone + Integer + Neg<Output=T>
impl<'a, T> Neg for &'a Ratio<T> where T: Clone + Integer + Neg<Output=T>
impl<T: Clone + Integer> Zero for Ratio<T>
impl<T: Clone + Integer> One for Ratio<T>
impl<T: Clone + Integer> Num for Ratio<T>
type FromStrRadixErr = ParseRatioError
fn from_str_radix(s: &str, radix: u32) -> Result<Ratio<T>, ParseRatioError>
Parses numer/denom
where the numbers are in base radix
.
impl<T: Clone + Integer + Signed> Signed for Ratio<T>
fn abs(&self) -> Ratio<T>
fn abs_sub(&self, other: &Ratio<T>) -> Ratio<T>
fn signum(&self) -> Ratio<T>
fn is_positive(&self) -> bool
fn is_negative(&self) -> bool
impl<T> Display for Ratio<T> where T: Display + Eq + One
impl<T: FromStr + Clone + Integer> FromStr for Ratio<T>
type Err = ParseRatioError
fn from_str(s: &str) -> Result<Ratio<T>, ParseRatioError>
Parses numer/denom
or just numer
.