Пример #1
0
        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));
        }
Пример #2
0
        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;
        }