Function: math-gcd
math-gcd is a byte-compiled function defined in calc-ext.el.gz.
Signature
(math-gcd A B)
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-ext.el.gz
;;; Compute the greatest common divisor of A and B. [I I I] [Public]
(defun math-gcd (a b)
(cond ((not (or (consp a) (consp b)))
(if (< a 0) (setq a (- a)))
(if (< b 0) (setq b (- b)))
(let (c)
(if (< a b)
(setq c b b a a c))
(while (> b 0)
(setq c b
b (% a b)
a c))
a))
((eq a 0) b)
((eq b 0) a)
(t
(if (Math-integer-negp a) (setq a (math-neg a)))
(if (Math-integer-negp b) (setq b (math-neg b)))
(let (c)
(if (< a b)
(setq c b b a a c))
(while (and (consp a) (not (eq b 0)))
(setq c b
b (math-imod a b)
a c))
(while (> b 0)
(setq c b
b (% a b)
a c))
a))))