summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorWolfgang Jenkner <wjenkner@inode.at>2015-01-15 20:02:17 +0100
committerWolfgang Jenkner <wjenkner@inode.at>2015-01-15 23:54:00 +0100
commit2290000ed69b1157739c280f090e5b60112e83fe (patch)
treef99e98a90548c979fa53347344d307bf25f225c1 /lisp
parentb577fe28c73cacfd1e81dca5ebf8cc7b0830d957 (diff)
downloademacs-2290000ed69b1157739c280f090e5b60112e83fe.tar.gz
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 @@
+2015-01-15 Wolfgang Jenkner <wjenkner@inode.at>
+
+ * 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)
+
2015-01-15 Stefan Monnier <monnier@iro.umontreal.ca>
* 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."
(and (consp expr)
(if (eq (car expr) 'var)
(math-check-unit-name expr)
- (and (or sub-exprs
- (memq (car expr) '(* / ^)))
- (or (math-units-in-expr-p (nth 1 expr) sub-exprs)
- (math-units-in-expr-p (nth 2 expr) sub-exprs))))))
+ (if (eq (car expr) 'neg)
+ (math-units-in-expr-p (nth 1 expr) sub-exprs)
+ (and (or sub-exprs
+ (memq (car expr) '(* / ^)))
+ (or (math-units-in-expr-p (nth 1 expr) sub-exprs)
+ (math-units-in-expr-p (nth 2 expr) sub-exprs)))))))
(defun math-only-units-in-expr-p (expr)
(and (consp expr)
@@ -924,6 +926,8 @@ If COMP or STD is non-nil, put that in the units table instead."
(cond ((math-scalarp expr) nil)
((eq (car expr) 'var)
(math-check-unit-name expr))
+ ((eq (car expr) 'neg)
+ (math-single-units-in-expr-p (nth 1 expr)))
((eq (car expr) '*)
(let ((u1 (math-single-units-in-expr-p (nth 1 expr)))
(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."
((eq (car-safe expr) '/)
(or (math-find-compatible-unit-rec (nth 1 expr) pow)
(math-find-compatible-unit-rec (nth 2 expr) (- pow))))
+ ((eq (car-safe expr) 'neg)
+ (math-find-compatible-unit-rec (nth 1 expr) pow))
((and (eq (car-safe expr) '^)
(integerp (nth 2 expr)))
(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."
((memq (car-safe expr) '(* /))
(cons (car expr)
(mapcar 'math-extract-units (cdr expr))))
+ ((eq (car-safe expr) 'neg)
+ (math-extract-units (nth 1 expr)))
((eq (car-safe expr) '^)
(list '^ (math-extract-units (nth 1 expr)) (nth 2 expr)))
((math-check-unit-name expr) expr)