aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorWolfgang Jenkner2015-01-15 20:02:17 +0100
committerWolfgang Jenkner2015-01-15 23:54:00 +0100
commit2290000ed69b1157739c280f090e5b60112e83fe (patch)
treef99e98a90548c979fa53347344d307bf25f225c1 /lisp
parentb577fe28c73cacfd1e81dca5ebf8cc7b0830d957 (diff)
downloademacs-2290000ed69b1157739c280f090e5b60112e83fe.tar.gz
emacs-2290000ed69b1157739c280f090e5b60112e83fe.zip
Handle the `neg' operator in some calc-units functions.
* lisp/calc/calc-units.el (math-units-in-expr-p) (math-single-units-in-expr-p, math-find-compatible-unit-rec) (math-extract-units): Handle the `neg' operator. (Bug#19582) * test/automated/calc-tests.el (calc-tests-equal, calc-tests-simple): New functions. (test-calc-remove-units, test-calc-extract-units) (test-calc-convert-units): New tests.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/calc/calc-units.el16
2 files changed, 18 insertions, 4 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index b7a38af9609..150f32f351a 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12015-01-15 Wolfgang Jenkner <wjenkner@inode.at>
2
3 * calc/calc-units.el (math-units-in-expr-p)
4 (math-single-units-in-expr-p, math-find-compatible-unit-rec)
5 (math-extract-units): Handle the `neg' operator. (Bug#19582)
6
12015-01-15 Stefan Monnier <monnier@iro.umontreal.ca> 72015-01-15 Stefan Monnier <monnier@iro.umontreal.ca>
2 8
3 * emacs-lisp/eieio-core.el: Provide support for cl-generic. 9 * emacs-lisp/eieio-core.el: Provide support for cl-generic.
diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el
index 26a644a29ba..05950864a52 100644
--- a/lisp/calc/calc-units.el
+++ b/lisp/calc/calc-units.el
@@ -904,10 +904,12 @@ If COMP or STD is non-nil, put that in the units table instead."
904 (and (consp expr) 904 (and (consp expr)
905 (if (eq (car expr) 'var) 905 (if (eq (car expr) 'var)
906 (math-check-unit-name expr) 906 (math-check-unit-name expr)
907 (and (or sub-exprs 907 (if (eq (car expr) 'neg)
908 (memq (car expr) '(* / ^))) 908 (math-units-in-expr-p (nth 1 expr) sub-exprs)
909 (or (math-units-in-expr-p (nth 1 expr) sub-exprs) 909 (and (or sub-exprs
910 (math-units-in-expr-p (nth 2 expr) sub-exprs)))))) 910 (memq (car expr) '(* / ^)))
911 (or (math-units-in-expr-p (nth 1 expr) sub-exprs)
912 (math-units-in-expr-p (nth 2 expr) sub-exprs)))))))
911 913
912(defun math-only-units-in-expr-p (expr) 914(defun math-only-units-in-expr-p (expr)
913 (and (consp expr) 915 (and (consp expr)
@@ -924,6 +926,8 @@ If COMP or STD is non-nil, put that in the units table instead."
924 (cond ((math-scalarp expr) nil) 926 (cond ((math-scalarp expr) nil)
925 ((eq (car expr) 'var) 927 ((eq (car expr) 'var)
926 (math-check-unit-name expr)) 928 (math-check-unit-name expr))
929 ((eq (car expr) 'neg)
930 (math-single-units-in-expr-p (nth 1 expr)))
927 ((eq (car expr) '*) 931 ((eq (car expr) '*)
928 (let ((u1 (math-single-units-in-expr-p (nth 1 expr))) 932 (let ((u1 (math-single-units-in-expr-p (nth 1 expr)))
929 (u2 (math-single-units-in-expr-p (nth 2 expr)))) 933 (u2 (math-single-units-in-expr-p (nth 2 expr))))
@@ -1079,6 +1083,8 @@ If COMP or STD is non-nil, put that in the units table instead."
1079 ((eq (car-safe expr) '/) 1083 ((eq (car-safe expr) '/)
1080 (or (math-find-compatible-unit-rec (nth 1 expr) pow) 1084 (or (math-find-compatible-unit-rec (nth 1 expr) pow)
1081 (math-find-compatible-unit-rec (nth 2 expr) (- pow)))) 1085 (math-find-compatible-unit-rec (nth 2 expr) (- pow))))
1086 ((eq (car-safe expr) 'neg)
1087 (math-find-compatible-unit-rec (nth 1 expr) pow))
1082 ((and (eq (car-safe expr) '^) 1088 ((and (eq (car-safe expr) '^)
1083 (integerp (nth 2 expr))) 1089 (integerp (nth 2 expr)))
1084 (math-find-compatible-unit-rec (nth 1 expr) (* pow (nth 2 expr)))) 1090 (math-find-compatible-unit-rec (nth 1 expr) (* pow (nth 2 expr))))
@@ -1497,6 +1503,8 @@ If COMP or STD is non-nil, put that in the units table instead."
1497 ((memq (car-safe expr) '(* /)) 1503 ((memq (car-safe expr) '(* /))
1498 (cons (car expr) 1504 (cons (car expr)
1499 (mapcar 'math-extract-units (cdr expr)))) 1505 (mapcar 'math-extract-units (cdr expr))))
1506 ((eq (car-safe expr) 'neg)
1507 (math-extract-units (nth 1 expr)))
1500 ((eq (car-safe expr) '^) 1508 ((eq (car-safe expr) '^)
1501 (list '^ (math-extract-units (nth 1 expr)) (nth 2 expr))) 1509 (list '^ (math-extract-units (nth 1 expr)) (nth 2 expr)))
1502 ((math-check-unit-name expr) expr) 1510 ((math-check-unit-name expr) expr)