std::ops::Div examples: correct nominator to numerator
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
parent
3750348daf
commit
38264937fc
@ -220,21 +220,21 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
|||||||
/// // derive `Eq` and `PartialEq`.
|
/// // derive `Eq` and `PartialEq`.
|
||||||
/// #[derive(Debug, Eq, PartialEq)]
|
/// #[derive(Debug, Eq, PartialEq)]
|
||||||
/// struct Rational {
|
/// struct Rational {
|
||||||
/// nominator: usize,
|
/// numerator: usize,
|
||||||
/// denominator: usize,
|
/// denominator: usize,
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl Rational {
|
/// impl Rational {
|
||||||
/// fn new(nominator: usize, denominator: usize) -> Self {
|
/// fn new(numerator: usize, denominator: usize) -> Self {
|
||||||
/// if denominator == 0 {
|
/// if denominator == 0 {
|
||||||
/// panic!("Zero is an invalid denominator!");
|
/// panic!("Zero is an invalid denominator!");
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // Reduce to lowest terms by dividing by the greatest common
|
/// // Reduce to lowest terms by dividing by the greatest common
|
||||||
/// // divisor.
|
/// // divisor.
|
||||||
/// let gcd = gcd(nominator, denominator);
|
/// let gcd = gcd(numerator, denominator);
|
||||||
/// Rational {
|
/// Rational {
|
||||||
/// nominator: nominator / gcd,
|
/// numerator: numerator / gcd,
|
||||||
/// denominator: denominator / gcd,
|
/// denominator: denominator / gcd,
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
@ -245,9 +245,9 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
|||||||
/// type Output = Self;
|
/// type Output = Self;
|
||||||
///
|
///
|
||||||
/// fn mul(self, rhs: Self) -> Self {
|
/// fn mul(self, rhs: Self) -> Self {
|
||||||
/// let nominator = self.nominator * rhs.nominator;
|
/// let numerator = self.numerator * rhs.numerator;
|
||||||
/// let denominator = self.denominator * rhs.denominator;
|
/// let denominator = self.denominator * rhs.denominator;
|
||||||
/// Rational::new(nominator, denominator)
|
/// Rational::new(numerator, denominator)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
@ -340,21 +340,21 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
|||||||
/// // derive `Eq` and `PartialEq`.
|
/// // derive `Eq` and `PartialEq`.
|
||||||
/// #[derive(Debug, Eq, PartialEq)]
|
/// #[derive(Debug, Eq, PartialEq)]
|
||||||
/// struct Rational {
|
/// struct Rational {
|
||||||
/// nominator: usize,
|
/// numerator: usize,
|
||||||
/// denominator: usize,
|
/// denominator: usize,
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl Rational {
|
/// impl Rational {
|
||||||
/// fn new(nominator: usize, denominator: usize) -> Self {
|
/// fn new(numerator: usize, denominator: usize) -> Self {
|
||||||
/// if denominator == 0 {
|
/// if denominator == 0 {
|
||||||
/// panic!("Zero is an invalid denominator!");
|
/// panic!("Zero is an invalid denominator!");
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // Reduce to lowest terms by dividing by the greatest common
|
/// // Reduce to lowest terms by dividing by the greatest common
|
||||||
/// // divisor.
|
/// // divisor.
|
||||||
/// let gcd = gcd(nominator, denominator);
|
/// let gcd = gcd(numerator, denominator);
|
||||||
/// Rational {
|
/// Rational {
|
||||||
/// nominator: nominator / gcd,
|
/// numerator: numerator / gcd,
|
||||||
/// denominator: denominator / gcd,
|
/// denominator: denominator / gcd,
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
@ -365,13 +365,13 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
|
|||||||
/// type Output = Self;
|
/// type Output = Self;
|
||||||
///
|
///
|
||||||
/// fn div(self, rhs: Self) -> Self::Output {
|
/// fn div(self, rhs: Self) -> Self::Output {
|
||||||
/// if rhs.nominator == 0 {
|
/// if rhs.numerator == 0 {
|
||||||
/// panic!("Cannot divide by zero-valued `Rational`!");
|
/// panic!("Cannot divide by zero-valued `Rational`!");
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// let nominator = self.nominator * rhs.denominator;
|
/// let numerator = self.numerator * rhs.denominator;
|
||||||
/// let denominator = self.denominator * rhs.nominator;
|
/// let denominator = self.denominator * rhs.numerator;
|
||||||
/// Rational::new(nominator, denominator)
|
/// Rational::new(numerator, denominator)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user