Commit cd559841 authored by Mattias Engdegård's avatar Mattias Engdegård

Calc: add missing dynamic variable declarations

* lisp/calc/calc-alg.el (math-simplify-only, calc-simplify-mode)
(math-expand-formulas, calc-poly-div-remainder)
(math-living-dangerously, math-simplifying, calc-angle-mode)
(calc-prefer-frac, math-poly-base-variable):
Declare dynamic variables.
* test/lisp/calc/calc-tests.el (calc-poly-div):
Add test for at least one bug caused by missing declarations.
parent e8aa6f19
Pipeline #4406 failed with stage
in 79 minutes and 48 seconds
......@@ -30,6 +30,8 @@
;;; Algebra commands.
(defvar math-simplify-only)
(defun calc-alg-evaluate (arg)
(interactive "p")
(calc-slow-wrapper
......@@ -38,6 +40,8 @@
(calc-modify-simplify-mode arg)
(calc-enter-result 1 "dsmp" (calc-top 1))))))
(defvar calc-simplify-mode)
(defun calc-modify-simplify-mode (arg)
(if (= (math-abs arg) 2)
(setq calc-simplify-mode 'alg)
......@@ -67,6 +71,8 @@
(calc-with-default-simplification
(calc-enter-result 1 "esmp" (math-simplify-extended (calc-top-n 1))))))
(defvar math-expand-formulas)
(defun calc-expand-formula (arg)
(interactive "p")
(calc-slow-wrapper
......@@ -160,6 +166,8 @@
(calc-binary-op "pgcd" 'calcFunc-pgcd arg)))
(defvar calc-poly-div-remainder)
(defun calc-poly-div (arg)
(interactive "P")
(calc-slow-wrapper
......@@ -303,6 +311,7 @@
(math-beforep (car a) (car b)))))
(t (string-lessp (car a) (car b)))))
(defvar math-living-dangerously)
(defsubst math-simplify-extended (a)
(let ((math-living-dangerously t))
......@@ -363,6 +372,9 @@
;; math-normalize-error is declared in calc.el.
(defvar math-normalize-error)
(defvar math-simplifying)
(defvar calc-angle-mode)
(defun math-simplify (top-expr)
(let ((math-simplifying t)
(calc-angle-mode (if (calc-input-angle-units top-expr)
......@@ -677,6 +689,8 @@ and should return the simplified expression to use (or nil)."
(math-make-frac (math-gcd (nth 1 a) (nth 1 b))
(math-gcd (nth 2 a) (nth 2 b)))))))
(defvar calc-prefer-frac)
(math-defsimplify %
(and (Math-realp (nth 2 expr))
(Math-posp (nth 2 expr))
......@@ -1671,6 +1685,7 @@ and should return the simplified expression to use (or nil)."
(defvar math-is-poly-degree)
(defvar math-is-poly-loose)
(defvar math-var)
(defvar math-poly-base-variable)
(defun math-is-polynomial (expr var &optional degree loose)
(let* ((math-poly-base-variable (if loose
......
......@@ -318,6 +318,21 @@ An existing calc stack is reused, otherwise a new one is created."
'(vec (calcFunc-eq (var x var-x) 3)
(calcFunc-eq (var y var-y) 0)))))
(ert-deftest calc-poly-div ()
"Test polynomial division, and that the remainder is recorded in the trail."
(with-current-buffer (calc-trail-buffer)
(let ((inhibit-read-only t))
(erase-buffer)
(calc-eval "2x**3+1" 'push)
(calc-eval "x**2+2x" 'push)
(calc-poly-div nil)
(let ((tos (calc-top-n 1))
(trail (buffer-string)))
(calc-pop 0)
(should (equal tos '(- (* 2 (var x var-x)) 4)))
(should (equal trail "pdiv 2 * x - 4\nprem 8 * x + 1\n"))))))
(provide 'calc-tests)
;;; calc-tests.el ends here
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment