Function: math-abs
math-abs is an autoloaded and byte-compiled function defined in
calc-arith.el.gz.
Signature
(math-abs A)
Aliases
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-arith.el.gz
;;; Compute the absolute value of A. [O O; r r] [Public]
(defun math-abs (a)
(cond ((Math-negp a)
(math-neg a))
((Math-anglep a)
a)
((eq (car a) 'cplx)
(math-hypot (nth 1 a) (nth 2 a)))
((eq (car a) 'polar)
(nth 1 a))
((eq (car a) 'vec)
(if (cdr (cdr (cdr a)))
(math-sqrt (calcFunc-abssqr a))
(if (cdr (cdr a))
(math-hypot (nth 1 a) (nth 2 a))
(if (cdr a)
(math-abs (nth 1 a))
a))))
((eq (car a) 'sdev)
(list 'sdev (math-abs (nth 1 a)) (nth 2 a)))
((and (eq (car a) 'intv) (math-intv-constp a))
(if (Math-posp a)
a
(let* ((nlo (math-neg (nth 2 a)))
(res (math-compare nlo (nth 3 a))))
(cond ((= res 1)
(math-make-intv (if (memq (nth 1 a) '(0 1)) 2 3) 0 nlo))
((= res 0)
(math-make-intv (if (eq (nth 1 a) 0) 2 3) 0 nlo))
(t
(math-make-intv (if (memq (nth 1 a) '(0 2)) 2 3)
0 (nth 3 a)))))))
((math-looks-negp a)
(list 'calcFunc-abs (math-neg a)))
((let ((signs (math-possible-signs a)))
(or (and (memq signs '(2 4 6)) a)
(and (memq signs '(1 3)) (math-neg a)))))
((let ((inf (math-infinitep a)))
(and inf
(if (equal inf '(var nan var-nan))
inf
'(var inf var-inf)))))
(t (calc-record-why 'numvecp a)
(list 'calcFunc-abs a))))