• (gcd a b)
(gcd a b) returns the greatest common divisor of a and b

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/math.clj:162 top

(defn gcd "(gcd a b) returns the greatest common divisor of a and b" [a b]
  (if (or (not (integer? a)) (not (integer? b)))
    (throw (IllegalArgumentException. "gcd requires two integers"))  
    (loop [a (abs a) b (abs b)]
      (if (zero? b) a,
	  (recur b (mod a b))))))
Vars in clojure.contrib.math/gcd: defn integer? loop mod not or zero?
Used in 0 other vars

Comments top

No comments for gcd. Log in to add a comment.