diff --git a/src/num.rs b/src/num.rs index bfb7dd3..36ba60c 100644 --- a/src/num.rs +++ b/src/num.rs @@ -258,6 +258,7 @@ mod tests { #[test] fn test_gcd() { assert_eq!(u8::gcd(2, 2), 2); + assert_eq!(u8::gcd(2, 8), 2); assert_eq!(u16::gcd(36, 48), 12); } diff --git a/src/rational.rs b/src/rational.rs index 9a62f0d..2acfef0 100644 --- a/src/rational.rs +++ b/src/rational.rs @@ -70,6 +70,10 @@ impl Frac { /// Generally, you will probably prefer to use the [frac!](../macro.frac.html) macro /// instead, as that accepts both signed and unsigned arguments pub fn new(n: T, d: T, s: Sign) -> Frac { + Self::new_raw(n, d, s).reduce() + } + + fn new_raw(n: T, d: T, s: Sign) -> Frac { if d.is_zero() { panic!("Fraction can not have a zero denominator"); } @@ -79,7 +83,6 @@ impl Frac { denom: d, sign: s, } - .reduce() } /// Determine the output sign given the two input signs @@ -121,17 +124,20 @@ impl + Sub + Mul + Div