Function: math-div-mod
math-div-mod is an autoloaded and byte-compiled function defined in
calc-forms.el.gz.
Signature
(math-div-mod A B M)
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-forms.el.gz
(defun math-div-mod (a b m) ; [R R R R] (Returns nil if no solution)
(and (Math-integerp a) (Math-integerp b) (Math-integerp m)
(let ((u1 1) (u3 b) (v1 0) (v3 m))
(while (not (eq v3 0)) ; See Knuth sec 4.5.2, exercise 15
(let* ((q (math-idivmod u3 v3))
(t1 (math-sub u1 (math-mul v1 (car q)))))
(setq u1 v1 u3 v3 v1 t1 v3 (cdr q))))
(let ((q (math-idivmod a u3)))
(and (eq (cdr q) 0)
(math-mod (math-mul (car q) u1) m))))))