Пример #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)));
        }
Пример #2
0
 /* Assumes x and y are both canonicalized. */
 public static bool equals(RatNum x, RatNum y)
 {
     return(IntNum.equals(x.numerator(), y.numerator()) &&
            IntNum.equals(x.denominator(), y.denominator()));
 }