public static Fraction operator +(Fraction f1, Fraction f2) { var lowestCommonMultiple = NumberTheory.LowestCommonMultiple(f1.m_Denominator, f2.m_Denominator); return(new Fraction(f1.m_Numerator * lowestCommonMultiple / f1.m_Denominator + f2.m_Numerator * lowestCommonMultiple / f2.m_Denominator, lowestCommonMultiple)); }
public Fraction(int numerator, int denominator = 1) { if (denominator == 0) { throw new ArgumentException(nameof(denominator)); } var gcd = NumberTheory.GreatestCommonDivisor(numerator, denominator) * Math.Sign(denominator); m_Numerator = numerator / gcd; m_Denominator = denominator / gcd; }