   }
   
   /// Compute the greatest common divisor for `x` and `y`.
-  public static func gcd(var x: T, var _ y: T) -> T {
-    var rest = x % y
+  public static func gcd(x: T, _ y: T) -> T {
+    var (x, y, rest) = (x, y, x % y)
     while rest > 0 {
       x = y
       y = rest
       rest = x % y
     }
     return y
+  }
+  
+  /// Compute the least common multiplier of `x` and `y`.
+  public static func lcm(x: T, _ y: T) -> T {
+    var abs = x * y
+    if abs < 0 {
+      abs = -abs
+    }
+    return abs / Rational.gcd(x, y)
   }
   
   /// Determine the smallest common denominator between `self` and `other` and return

    let (res, overflow3) = Rational.rationalWithOverflow(numer, denom)
    return (res, overflow1 || overflow2 || overflow3)
  }
}



  /// Raises this rational value to the power of `exp`.
  public func toPowerOf(exp: T) -> Rational<T> {
    return Rational(pow(numerator, exp), pow(denominator, exp))
  }
  
  /// Returns the greatest common denominator for the two given rational numbers
  public static func gcd(x: Rational<T>, _ y: Rational<T>) -> Rational<T> {
    return Rational(Rational.gcd(x.numerator, y.numerator),
                    Rational.lcm(x.denominator, y.denominator))
  }
  
  /// Returns the least common multiplier for the two given rational numbers
  public static func lcm(x: Rational<T>, _ y: Rational<T>) -> Rational<T> {
    let (xn, yn, denom) = x.commonDenomWith(y)
    return Rational(Rational.lcm(xn, yn), denom)
  }
}

