Function: math-combine-sum

math-combine-sum is an autoloaded and byte-compiled function defined in calc-arith.el.gz.

Signature

(math-combine-sum A B NEGA NEGB SCALAR-OKAY)

Source Code

;; Defined in /usr/src/emacs/lisp/calc/calc-arith.el.gz
;;; Combine two terms being added, if possible.
(defun math-combine-sum (a b nega negb scalar-okay)
  (if (and scalar-okay (Math-objvecp a) (Math-objvecp b))
      (math-add-or-sub a b nega negb)
    (let ((amult 1) (bmult 1))
      (and (consp a)
	   (cond ((and (eq (car a) '*)
		       (Math-objectp (nth 1 a)))
		  (setq amult (nth 1 a)
			a (nth 2 a)))
		 ((and (eq (car a) '/)
		       (Math-objectp (nth 2 a)))
		  (setq amult (if (Math-integerp (nth 2 a))
				  (list 'frac 1 (nth 2 a))
				(math-div 1 (nth 2 a)))
			a (nth 1 a)))
		 ((eq (car a) 'neg)
		  (setq amult -1
			a (nth 1 a)))))
      (and (consp b)
	   (cond ((and (eq (car b) '*)
		       (Math-objectp (nth 1 b)))
		  (setq bmult (nth 1 b)
			b (nth 2 b)))
		 ((and (eq (car b) '/)
		       (Math-objectp (nth 2 b)))
		  (setq bmult (if (Math-integerp (nth 2 b))
				  (list 'frac 1 (nth 2 b))
				(math-div 1 (nth 2 b)))
			b (nth 1 b)))
		 ((eq (car b) 'neg)
		  (setq bmult -1
			b (nth 1 b)))))
      (and (if math-simplifying
	       (Math-equal a b)
	     (equal a b))
	   (progn
	     (if nega (setq amult (math-neg amult)))
	     (if negb (setq bmult (math-neg bmult)))
	     (setq amult (math-add amult bmult))
	     (math-mul amult a))))))