Function: calc-explain-units-rec
calc-explain-units-rec is a byte-compiled function defined in
calc-units.el.gz.
Signature
(calc-explain-units-rec EXPR POW)
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-units.el.gz
(defun calc-explain-units-rec (expr pow)
(let ((u (math-check-unit-name expr))
pos)
(if (and u (not (math-zerop pow)))
(let ((name (or (nth 2 u) (symbol-name (car u)))))
(if (eq (aref name 0) ?\*)
(setq name (substring name 1)))
(if (string-match "[^a-zA-Zα-ωΑ-Ω0-9']" name)
(if (string-match "^[a-zA-Zα-ωΑ-Ω0-9' ()]*$" name)
(while (setq pos (string-match "[ ()]" name))
(setq name (concat (substring name 0 pos)
(if (eq (aref name pos) 32) "-" "")
(substring name (1+ pos)))))
(setq name (concat "(" name ")"))))
(or (eq (nth 1 expr) (car u))
(setq name (concat (nth 2 (assq (aref (symbol-name (nth 1 expr))
0)
math-unit-prefixes))
(if (and (string-match "[^a-zA-Zα-ωΑ-Ω0-9']" name)
(not (memq (car u) '(mHg gf))))
(concat "-" name)
(downcase name)))))
(cond ((or (math-equal-int pow 1)
(math-equal-int pow -1)))
((or (math-equal-int pow 2)
(math-equal-int pow -2))
(if (equal (nth 4 u) '((m . 1)))
(setq name (concat "Square-" name))
(setq name (concat name "-squared"))))
((or (math-equal-int pow 3)
(math-equal-int pow -3))
(if (equal (nth 4 u) '((m . 1)))
(setq name (concat "Cubic-" name))
(setq name (concat name "-cubed"))))
(t
(setq name (concat name "^"
(math-format-number (math-abs pow))))))
(if (math-posp pow)
(setq calc-num-units (if calc-num-units
(concat calc-num-units " " name)
name))
(setq calc-den-units (if calc-den-units
(concat calc-den-units " " name)
name))))
(cond ((eq (car-safe expr) '*)
(calc-explain-units-rec (nth 1 expr) pow)
(calc-explain-units-rec (nth 2 expr) pow))
((eq (car-safe expr) '/)
(calc-explain-units-rec (nth 1 expr) pow)
(calc-explain-units-rec (nth 2 expr) (- pow)))
((memq (car-safe expr) '(neg + -))
(calc-explain-units-rec (nth 1 expr) pow))
((and (eq (car-safe expr) '^)
(math-realp (nth 2 expr)))
(calc-explain-units-rec (nth 1 expr)
(math-mul pow (nth 2 expr))))))))