Function: math-round
math-round is an autoloaded and byte-compiled function defined in
calc-arith.el.gz.
Signature
(math-round A &optional PREC)
Aliases
Source Code
;; Defined in /usr/src/emacs/lisp/calc/calc-arith.el.gz
;;; Coerce A to be an integer (by rounding to nearest integer). [I N] [Public]
(defun math-round (a &optional prec)
(cond (prec
(if (Math-messy-integerp prec)
(setq prec (math-trunc prec)))
(or (integerp prec)
(math-reject-arg prec 'fixnump))
(if (and (<= prec 0)
(math-provably-integerp a))
a
(calcFunc-scf (math-round (let ((calc-prefer-frac t))
(calcFunc-scf a prec)))
(- prec))))
((Math-anglep a)
(if (Math-num-integerp a)
(math-trunc a)
(if (and (Math-negp a) (not (eq math-rounding-mode 'up)))
(math-neg (math-round (math-neg a)))
(setq a (let ((calc-angle-mode 'deg)) ; in case of HMS forms
(math-add a (if (Math-ratp a)
'(frac 1 2)
'(float 5 -1)))))
(if (and (Math-num-integerp a) (eq math-rounding-mode 'even))
(progn
(setq a (math-floor a))
(or (math-evenp a)
(setq a (math-sub a 1)))
a)
(math-floor a)))))
((math-provably-integerp a) a)
((eq (car a) 'date) (list 'date (math-round (nth 1 a))))
((eq (car a) 'intv)
(math-floor (math-add a '(frac 1 2))))
((Math-vectorp a)
(math-map-vec (lambda (x) (math-round x prec)) a))
((math-infinitep a)
(if (or (math-posp a) (math-negp a))
a
'(var nan var-nan)))
((math-to-integer a))
(t (math-reject-arg a 'anglep))))