diff options
| author | Mattias EngdegÄrd | 2019-12-26 19:37:10 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2019-12-26 19:37:10 +0100 |
| commit | cd559841537726315d72a303447140f71e34f635 (patch) | |
| tree | 144f2d9569876ecadc816192ea5b24ed599ca5b2 | |
| parent | e8aa6f19e99e5de9a3953fef8ae50e2363531b3d (diff) | |
| download | emacs-cd559841537726315d72a303447140f71e34f635.tar.gz emacs-cd559841537726315d72a303447140f71e34f635.zip | |
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.
| -rw-r--r-- | lisp/calc/calc-alg.el | 15 | ||||
| -rw-r--r-- | test/lisp/calc/calc-tests.el | 15 |
2 files changed, 30 insertions, 0 deletions
diff --git a/lisp/calc/calc-alg.el b/lisp/calc/calc-alg.el index c3efeeeb62c..4905a455aba 100644 --- a/lisp/calc/calc-alg.el +++ b/lisp/calc/calc-alg.el | |||
| @@ -30,6 +30,8 @@ | |||
| 30 | 30 | ||
| 31 | ;;; Algebra commands. | 31 | ;;; Algebra commands. |
| 32 | 32 | ||
| 33 | (defvar math-simplify-only) | ||
| 34 | |||
| 33 | (defun calc-alg-evaluate (arg) | 35 | (defun calc-alg-evaluate (arg) |
| 34 | (interactive "p") | 36 | (interactive "p") |
| 35 | (calc-slow-wrapper | 37 | (calc-slow-wrapper |
| @@ -38,6 +40,8 @@ | |||
| 38 | (calc-modify-simplify-mode arg) | 40 | (calc-modify-simplify-mode arg) |
| 39 | (calc-enter-result 1 "dsmp" (calc-top 1)))))) | 41 | (calc-enter-result 1 "dsmp" (calc-top 1)))))) |
| 40 | 42 | ||
| 43 | (defvar calc-simplify-mode) | ||
| 44 | |||
| 41 | (defun calc-modify-simplify-mode (arg) | 45 | (defun calc-modify-simplify-mode (arg) |
| 42 | (if (= (math-abs arg) 2) | 46 | (if (= (math-abs arg) 2) |
| 43 | (setq calc-simplify-mode 'alg) | 47 | (setq calc-simplify-mode 'alg) |
| @@ -67,6 +71,8 @@ | |||
| 67 | (calc-with-default-simplification | 71 | (calc-with-default-simplification |
| 68 | (calc-enter-result 1 "esmp" (math-simplify-extended (calc-top-n 1)))))) | 72 | (calc-enter-result 1 "esmp" (math-simplify-extended (calc-top-n 1)))))) |
| 69 | 73 | ||
| 74 | (defvar math-expand-formulas) | ||
| 75 | |||
| 70 | (defun calc-expand-formula (arg) | 76 | (defun calc-expand-formula (arg) |
| 71 | (interactive "p") | 77 | (interactive "p") |
| 72 | (calc-slow-wrapper | 78 | (calc-slow-wrapper |
| @@ -160,6 +166,8 @@ | |||
| 160 | (calc-binary-op "pgcd" 'calcFunc-pgcd arg))) | 166 | (calc-binary-op "pgcd" 'calcFunc-pgcd arg))) |
| 161 | 167 | ||
| 162 | 168 | ||
| 169 | (defvar calc-poly-div-remainder) | ||
| 170 | |||
| 163 | (defun calc-poly-div (arg) | 171 | (defun calc-poly-div (arg) |
| 164 | (interactive "P") | 172 | (interactive "P") |
| 165 | (calc-slow-wrapper | 173 | (calc-slow-wrapper |
| @@ -303,6 +311,7 @@ | |||
| 303 | (math-beforep (car a) (car b))))) | 311 | (math-beforep (car a) (car b))))) |
| 304 | (t (string-lessp (car a) (car b))))) | 312 | (t (string-lessp (car a) (car b))))) |
| 305 | 313 | ||
| 314 | (defvar math-living-dangerously) | ||
| 306 | 315 | ||
| 307 | (defsubst math-simplify-extended (a) | 316 | (defsubst math-simplify-extended (a) |
| 308 | (let ((math-living-dangerously t)) | 317 | (let ((math-living-dangerously t)) |
| @@ -363,6 +372,9 @@ | |||
| 363 | 372 | ||
| 364 | ;; math-normalize-error is declared in calc.el. | 373 | ;; math-normalize-error is declared in calc.el. |
| 365 | (defvar math-normalize-error) | 374 | (defvar math-normalize-error) |
| 375 | (defvar math-simplifying) | ||
| 376 | (defvar calc-angle-mode) | ||
| 377 | |||
| 366 | (defun math-simplify (top-expr) | 378 | (defun math-simplify (top-expr) |
| 367 | (let ((math-simplifying t) | 379 | (let ((math-simplifying t) |
| 368 | (calc-angle-mode (if (calc-input-angle-units top-expr) | 380 | (calc-angle-mode (if (calc-input-angle-units top-expr) |
| @@ -677,6 +689,8 @@ and should return the simplified expression to use (or nil)." | |||
| 677 | (math-make-frac (math-gcd (nth 1 a) (nth 1 b)) | 689 | (math-make-frac (math-gcd (nth 1 a) (nth 1 b)) |
| 678 | (math-gcd (nth 2 a) (nth 2 b))))))) | 690 | (math-gcd (nth 2 a) (nth 2 b))))))) |
| 679 | 691 | ||
| 692 | (defvar calc-prefer-frac) | ||
| 693 | |||
| 680 | (math-defsimplify % | 694 | (math-defsimplify % |
| 681 | (and (Math-realp (nth 2 expr)) | 695 | (and (Math-realp (nth 2 expr)) |
| 682 | (Math-posp (nth 2 expr)) | 696 | (Math-posp (nth 2 expr)) |
| @@ -1671,6 +1685,7 @@ and should return the simplified expression to use (or nil)." | |||
| 1671 | (defvar math-is-poly-degree) | 1685 | (defvar math-is-poly-degree) |
| 1672 | (defvar math-is-poly-loose) | 1686 | (defvar math-is-poly-loose) |
| 1673 | (defvar math-var) | 1687 | (defvar math-var) |
| 1688 | (defvar math-poly-base-variable) | ||
| 1674 | 1689 | ||
| 1675 | (defun math-is-polynomial (expr var &optional degree loose) | 1690 | (defun math-is-polynomial (expr var &optional degree loose) |
| 1676 | (let* ((math-poly-base-variable (if loose | 1691 | (let* ((math-poly-base-variable (if loose |
diff --git a/test/lisp/calc/calc-tests.el b/test/lisp/calc/calc-tests.el index 3f5adceeff1..33e6b14827f 100644 --- a/test/lisp/calc/calc-tests.el +++ b/test/lisp/calc/calc-tests.el | |||
| @@ -318,6 +318,21 @@ An existing calc stack is reused, otherwise a new one is created." | |||
| 318 | '(vec (calcFunc-eq (var x var-x) 3) | 318 | '(vec (calcFunc-eq (var x var-x) 3) |
| 319 | (calcFunc-eq (var y var-y) 0))))) | 319 | (calcFunc-eq (var y var-y) 0))))) |
| 320 | 320 | ||
| 321 | (ert-deftest calc-poly-div () | ||
| 322 | "Test polynomial division, and that the remainder is recorded in the trail." | ||
| 323 | (with-current-buffer (calc-trail-buffer) | ||
| 324 | (let ((inhibit-read-only t)) | ||
| 325 | (erase-buffer) | ||
| 326 | |||
| 327 | (calc-eval "2x**3+1" 'push) | ||
| 328 | (calc-eval "x**2+2x" 'push) | ||
| 329 | (calc-poly-div nil) | ||
| 330 | (let ((tos (calc-top-n 1)) | ||
| 331 | (trail (buffer-string))) | ||
| 332 | (calc-pop 0) | ||
| 333 | (should (equal tos '(- (* 2 (var x var-x)) 4))) | ||
| 334 | (should (equal trail "pdiv 2 * x - 4\nprem 8 * x + 1\n")))))) | ||
| 335 | |||
| 321 | (provide 'calc-tests) | 336 | (provide 'calc-tests) |
| 322 | ;;; calc-tests.el ends here | 337 | ;;; calc-tests.el ends here |
| 323 | 338 | ||