Beispiel #1
0
        public static RationalNumber operator +(RationalNumber r1, RationalNumber r2)
        {
            RationalNumber result = new RationalNumber();

            result.Denominator = (uint)MathFunc.LCM((int)r1.Denominator, (int)r2.Denominator);
            result.Numerator   = r1.Numerator * ((int)result.Denominator / (int)r1.Denominator) +
                                 r2.Numerator * ((int)result.Denominator / (int)r2.Denominator);
            result.Reduce();
            return(result);
        }
Beispiel #2
0
        public static void CommonDenominator(RationalNumber r1, RationalNumber r2)
        {
            if (r1.Denominator == r2.Denominator)
            {
                return;
            }
            uint lcm   = (uint)MathFunc.LCM((int)r1.Denominator, (int)r2.Denominator);
            uint mult1 = lcm / r1.Denominator;
            uint mult2 = lcm / r2.Denominator;

            r1.Numerator  *= (int)mult1;
            r1.Denominator = lcm;
            r2.Numerator  *= (int)mult2;
            r2.Denominator = lcm;
        }