diff --git a/rational/src/lib.rs b/rational/src/lib.rs index 47bb0b0..db758bf 100644 --- a/rational/src/lib.rs +++ b/rational/src/lib.rs @@ -56,13 +56,13 @@ pub type Rational64 = Ratio; pub type BigRational = Ratio; impl Ratio { - /// Creates a ratio representing the integer `t`. + /// Creates a `Ratio` representing the integer `t`. #[inline] pub fn from_integer(t: T) -> Ratio { Ratio::new_raw(t, One::one()) } - /// Creates a ratio without checking for `denom == 0` or reducing. + /// Creates a `Ratio` without checking for `denom == 0` or reducing. #[inline] pub fn new_raw(numer: T, denom: T) -> Ratio { Ratio { @@ -71,7 +71,7 @@ impl Ratio { } } - /// Create a new Ratio. Fails if `denom == 0`. + /// Creates a new `Ratio`. Fails if `denom == 0`. #[inline] pub fn new(numer: T, denom: T) -> Ratio { if denom == Zero::zero() { @@ -82,7 +82,7 @@ impl Ratio { ret } - /// Converts to an integer. + /// Converts to an integer, rounding towards zero. #[inline] pub fn to_integer(&self) -> T { self.trunc().numer @@ -106,7 +106,7 @@ impl Ratio { self.denom == One::one() } - /// Put self into lowest terms, with denom > 0. + /// Puts self into lowest terms, with denom > 0. fn reduce(&mut self) { let g: T = self.numer.gcd(&self.denom); @@ -124,7 +124,10 @@ impl Ratio { } } - /// Returns a `reduce`d copy of self. + /// Returns a reduced copy of self. + /// + /// In general, it is not necessary to use this method, as the only + /// method of procuring a non-reduced fraction is through `new_raw`. pub fn reduced(&self) -> Ratio { let mut ret = self.clone(); ret.reduce(); @@ -201,7 +204,9 @@ impl Ratio { Ratio::from_integer(self.numer.clone() / self.denom.clone()) } - /// Returns the fractional part of a number. + /// Returns the fractional part of a number, with division rounded towards zero. + /// + /// Satisfies `self == self.trunc() + self.fract()`. #[inline] pub fn fract(&self) -> Ratio { Ratio::new_raw(self.numer.clone() % self.denom.clone(), self.denom.clone()) @@ -209,7 +214,7 @@ impl Ratio { } impl Ratio { - /// Raises the ratio to the power of an exponent + /// Raises the `Ratio` to the power of an exponent. #[inline] pub fn pow(&self, expon: i32) -> Ratio { match expon.cmp(&0) {