private void Normalize() { // compute greatest common divisor of numerator and denominator BigInteger g = Numerator.Gcd(Denominator); if (g.CompareTo(BigInteger.One) > 0) { Numerator = Numerator.Divide(g); Denominator = Denominator.Divide(g); } if (Denominator.CompareTo(BigInteger.Zero) == -1) { Numerator = Numerator.Negate(); Denominator = Denominator.Negate(); } }
public Fraction InLowestTerms() { var gcd = Numerator.Gcd(Denominator); return(new Fraction(Numerator / gcd, Denominator / gcd)); }