From c48e539226a062d01b8d5534644fae959506a743 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Thu, 18 May 2017 14:47:06 +0900 Subject: Use the expression angle units while simplifying it Don't use the angle mode, use the angle units included in the expression instead (Bug#23889). * lisp/calc/calc-alg.el (calc-input-angle-units): New defun. (math-simplify): Use it. * lisp/calc/calc-forms.el (math-to-hms, math-from-hms): Don't use calc-angle-mode if math-simplifying-units is non-nil. * lisp/calc/calc-math.el (calcFunc-nroot, math-from-radians) (math-to-radians-2, math-from-radians-2): Don't convert angle to radians if math-simplifying-units is non-nil. * test/lisp/calc/calc-tests.el (test-calc-23889): Add test. --- test/lisp/calc/calc-tests.el | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'test/lisp/calc') diff --git a/test/lisp/calc/calc-tests.el b/test/lisp/calc/calc-tests.el index 8f56d48d01d..68567dcc212 100644 --- a/test/lisp/calc/calc-tests.el +++ b/test/lisp/calc/calc-tests.el @@ -86,6 +86,50 @@ An existing calc stack is reused, otherwise a new one is created." (math-read-expr "1m") "cm") '(* -100 (var cm var-cm))))) +(ert-deftest test-calc-23889 () + "Test for http://debbugs.gnu.org/23889 and 25652." + (dolist (mode '(deg rad)) + (let ((calc-angle-mode mode)) + ;; If user inputs angle units, then should ignore `calc-angle-mode'. + (should (string= "5253" + (substring + (number-to-string + (nth 1 + (math-simplify-units + '(calcFunc-cos (* 45 (var rad var-rad)))))) + 0 4))) + (should (string= "7071" + (substring + (number-to-string + (nth 1 + (math-simplify-units + '(calcFunc-cos (* 45 (var deg var-deg)))))) + 0 4))) + (should (string= "8939" + (substring + (number-to-string + (nth 1 + (math-simplify-units + '(+ (calcFunc-sin (* 90 (var rad var-rad))) + (calcFunc-cos (* 90 (var deg var-deg))))))) + 0 4))) + (should (string= "5519" + (substring + (number-to-string + (nth 1 + (math-simplify-units + '(+ (calcFunc-sin (* 90 (var deg var-deg))) + (calcFunc-cos (* 90 (var rad var-rad))))))) + 0 4))) + ;; If user doesn't input units, then must use `calc-angle-mode'. + (should (string= (if (eq calc-angle-mode 'deg) + "9998" + "5403") + (substring + (number-to-string + (nth 1 (calcFunc-cos 1))) + 0 4)))))) + (provide 'calc-tests) ;;; calc-tests.el ends here -- cgit v1.2.1