Beispiel #1
0
        public static RatNum add(RatNum x, RatNum y, int k)
        {
            IntNum x_num = x.numerator();
            IntNum x_den = x.denominator();
            IntNum y_num = y.numerator();
            IntNum y_den = y.denominator();

            if (IntNum.equals(x_den, y_den))
            {
                return(RatNum.make(IntNum.add(x_num, y_num, k), x_den));
            }
            return(RatNum.make(IntNum.add(IntNum.times(y_den, x_num),
                                          IntNum.times(y_num, x_den), k),
                               IntNum.times(x_den, y_den)));
        }