Function: math-simplify-units-quotient

math-simplify-units-quotient is a byte-compiled function defined in calc-units.el.gz.

Signature

(math-simplify-units-quotient N D)

Source Code

;; Defined in /usr/src/emacs/lisp/calc/calc-units.el.gz
;; Simplify, e.g., "in / cm" to "2.54" in a units expression.
(defun math-simplify-units-quotient (n d)
  (let ((pow1 1)
	(pow2 1))
    (when (and (eq (car-safe n) '^)
	       (integerp (nth 2 n)))
      (setq pow1 (nth 2 n) n (nth 1 n)))
    (when (and (eq (car-safe d) '^)
	       (integerp (nth 2 d)))
      (setq pow2 (nth 2 d) d (nth 1 d)))
    (let ((un (math-check-unit-name n))
	  (ud (math-check-unit-name d)))
      (and un ud
	   (if (and (equal (nth 4 un) (nth 4 ud))
		    (eq pow1 pow2))
               (if (eq pow1 1)
                   (math-to-standard-units (list '/ n d) nil)
                 (list '^ (math-to-standard-units (list '/ n d) nil) pow1))
             (setq un (nth 4 un)
                   ud (nth 4 ud))
             (dolist (x un)
               (dolist (y ud)
                 (when (eq (car x) (car y))
                   (setq math-try-cancel-units
                         (+ math-try-cancel-units
                            (- (* (cdr x) pow1)
                               (* (cdr (car ud)) pow2))))))))))))