From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#25652: 26.0.50; calc says that cos(1 degree) is 0.54 Date: Mon, 13 Feb 2017 12:40:05 +0900 (JST) Message-ID: References: <877f51f7ze.fsf@wilson> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1486957278 13030 195.159.176.226 (13 Feb 2017 03:41:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 13 Feb 2017 03:41:18 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) To: 25652@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Feb 13 04:41:13 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cd7Vp-00031I-FS for geb-bug-gnu-emacs@m.gmane.org; Mon, 13 Feb 2017 04:41:13 +0100 Original-Received: from localhost ([::1]:54354 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cd7Vv-0004lm-0O for geb-bug-gnu-emacs@m.gmane.org; Sun, 12 Feb 2017 22:41:19 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42724) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cd7Vh-0004jd-D9 for bug-gnu-emacs@gnu.org; Sun, 12 Feb 2017 22:41:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cd7Ve-00070T-7F for bug-gnu-emacs@gnu.org; Sun, 12 Feb 2017 22:41:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39465) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cd7Ve-00070P-2a for bug-gnu-emacs@gnu.org; Sun, 12 Feb 2017 22:41:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cd7Vd-0001Jb-Sd for bug-gnu-emacs@gnu.org; Sun, 12 Feb 2017 22:41:01 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <877f51f7ze.fsf@wilson> Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 13 Feb 2017 03:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25652 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 25652-submit@debbugs.gnu.org id=B25652.14869572184992 (code B ref 25652); Mon, 13 Feb 2017 03:41:01 +0000 Original-Received: (at 25652) by debbugs.gnu.org; 13 Feb 2017 03:40:18 +0000 Original-Received: from localhost ([127.0.0.1]:37664 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cd7Uv-0001IS-Sx for submit@debbugs.gnu.org; Sun, 12 Feb 2017 22:40:18 -0500 Original-Received: from mail-pg0-f50.google.com ([74.125.83.50]:33950) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cd7Us-0001ID-Vu for 25652@debbugs.gnu.org; Sun, 12 Feb 2017 22:40:15 -0500 Original-Received: by mail-pg0-f50.google.com with SMTP id 14so28482803pgg.1 for <25652@debbugs.gnu.org>; Sun, 12 Feb 2017 19:40:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:subject:message-id:user-agent:mime-version; bh=JzAva2Kdb4IbKthIB8HIz0O+VbhkllqsQyeuspNcVnk=; b=OZb+Z2DAXtNjrKCPwEzdR/vweHL38BBHqsEitidF4A4jL2IHKIaFLibDJXRGvzNuYr qZxCwlEFsO3/q95A6wTk6cVeCbnA/5tT+DsujP32yTolPlC0/JBdo/Oi2oTe2nJpgXAE S5RvvWQhrUBfZ0yFRtUaiBgzuIdUZiC2ABFm32KraAP1NctXMEzsHjV2JcDOljCatTbQ Si7DAj4JUU5hCFEcqkPgttQt3RlkGIo5t2rmtFTayekWvuk3iUNAojhLDcGCj0Fa8vZI GGuX4XJPfsAfYMLRxSRMuBuK02tUb+soY78LasMPGYRPVRxg/wE0YwKjQfwkAb3/CMBT aicA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:subject:message-id:user-agent :mime-version; bh=JzAva2Kdb4IbKthIB8HIz0O+VbhkllqsQyeuspNcVnk=; b=ZeyMMpvGEYkHxbNGwWj/B3/dLkvHvMYaLp5oSZ5E2mTHE/uUBNnEkTx1ROB2DQk84c Lf0O7VaIzmxqCO2dz/q2PiD7Ic9HZVi2C8aiR5zPnvpx0NnjQLdLZn8SDDZBtiNNmw9m NTsaPWRH59ZGP5Yweg0I0CNCplbCkJUmH9jVp6fcW/EZIKQIwvnfkOannqqvN2N6EM2r CFmoNCNoBvqnlwFfo8fVBphHjOuyA5Lx/9OVhqlNiHiBzekOdWXBdoAGmml4JsBC4kgK tkVLyRURt/ikXdVsFa381S5Z94ukVoJw84cVrUY8DO4nIJFpOVCwbokVlbgD4WigHpiz xgwA== X-Gm-Message-State: AMke39kPX7Ieq8rqlqmGB4moWKyuB1b1+K+3zG0MAqethaiQyM6xNbEKsT7+PvTrvV+spA== X-Received: by 10.84.177.129 with SMTP id x1mr26777739plb.75.1486957208569; Sun, 12 Feb 2017 19:40:08 -0800 (PST) Original-Received: from calancha-pc (104.81.147.124.dy.bbexcite.jp. [124.147.81.104]) by smtp.gmail.com with ESMTPSA id l22sm17335910pgc.43.2017.02.12.19.40.06 for <25652@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Feb 2017 19:40:08 -0800 (PST) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:129296 Archived-At: [Forwading to the bug thread: Sorry if you receive this message twice] npostavs@users.sourceforge.net writes: > tags 25652 confirmed > retitle 25652 26.0.50; [calc] In Units Simplication + Degree mode cos(1 deg) != cos(1) > quit > > Torsten Bronger writes: >>> You can toggle this in calc mode with "m U". So "m d m U 1 C m U >>> 1 C" should exhibit the problem. Note that you have "Deg" active >>> the whole time. [...] >> >> After havin updated to current git master, I can now reproduce this >> on both of my machine. Can you confirm? > > Yes, this happens in units simplication mode. Note that 'cos(1 deg) RET > does give 0.999. It seems to be because of the fix for #23889 [1: > 713e922243]. Tino, any ideas? > > 1: 2016-07-12 00:38:14 +0900 713e922243fb60d850f7b0ff83f3e2a3682f1832 > Ignore angle mode while simplifying units Yes, my commit produced this bug. We must revert it. Sorry for that. That commit was to fix Bug#23889. It would be nice if we can fix Bug#23889 in a new way. In that bug the problem was that, if the user inputs a symbolic expression containning an angle unit, then this unit is overriden by calc-angle-mode while simplifying such expression. That should not happen as mentioned in the manual: (info "(calc) Trigonometric and Hyperbolic Functions") That is, M-x calc RET m d ; Set calc-angle-mode to degrees. ' sin (45 deg) RET u s ; Must insert the value of: (sin (* 45 pi (/ 180.0))) ;; But instead, inserts the value of: (sin (* 45 (expt (/ pi 180.0) 2))) ;; i.e., it's applying (/ pi 180) twice. I have updated the patch: 1) Revert 713e922243 2) Bind calc-angle-mode to 'rad while simplifying an expression whenever such expression contains an unit angle. This way, hopefully, the second factor (/ pi 180) won't be applied. Opinions, comments... ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From 1a2592409c0fcfca7826b71248d3d3d234355c13 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Sun, 12 Feb 2017 21:14:34 +0900 Subject: [PATCH 1/2] Revert 'Ignore angle mode while simplifying units' This commit (713e922243) cause regressions (Bug#25652). --- lisp/calc/calc-forms.el | 12 +++--------- lisp/calc/calc-math.el | 12 ++++-------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/lisp/calc/calc-forms.el b/lisp/calc/calc-forms.el index 6aa421ec20..abf76cf07e 100644 --- a/lisp/calc/calc-forms.el +++ b/lisp/calc/calc-forms.el @@ -317,9 +317,7 @@ math-to-hms (list 'calcFunc-hms a)) ((math-negp a) (math-neg (math-to-hms (math-neg a) ang))) - ((eq (or ang - (and (not math-simplifying-units) calc-angle-mode)) - 'rad) + ((eq (or ang calc-angle-mode) 'rad) (math-to-hms (math-div a (math-pi-over-180)) 'deg)) ((memq (car-safe a) '(cplx polar)) a) (t @@ -356,16 +354,12 @@ math-from-hms (if (eq (car-safe a) 'sdev) (math-make-sdev (math-from-hms (nth 1 a) ang) (math-from-hms (nth 2 a) ang)) - (if (eq (or ang - (and (not math-simplifying-units) calc-angle-mode)) - 'rad) + (if (eq (or ang calc-angle-mode) 'rad) (list 'calcFunc-rad a) (list 'calcFunc-deg a))))) ((math-negp a) (math-neg (math-from-hms (math-neg a) ang))) - ((eq (or ang - (and (not math-simplifying-units) calc-angle-mode)) - 'rad) + ((eq (or ang calc-angle-mode) 'rad) (math-mul (math-from-hms a 'deg) (math-pi-over-180))) (t (math-add (math-div (math-add (math-div (nth 3 a) diff --git a/lisp/calc/calc-math.el b/lisp/calc/calc-math.el index 2590761d53..faa318d45d 100644 --- a/lisp/calc/calc-math.el +++ b/lisp/calc/calc-math.el @@ -763,14 +763,12 @@ calcFunc-nroot (defun math-to-radians (a) ; [N N] (cond ((eq (car-safe a) 'hms) (math-from-hms a 'rad)) - ((and (not math-simplifying-units) - (memq calc-angle-mode '(deg hms))) + ((memq calc-angle-mode '(deg hms)) (math-mul a (math-pi-over-180))) (t a))) (defun math-from-radians (a) ; [N N] - (cond ((and (not math-simplifying-units) - (eq calc-angle-mode 'deg)) + (cond ((eq calc-angle-mode 'deg) (if (math-constp a) (math-div a (math-pi-over-180)) (list 'calcFunc-deg a))) @@ -781,16 +779,14 @@ math-from-radians (defun math-to-radians-2 (a &optional force-symbolic) ; [N N] (cond ((eq (car-safe a) 'hms) (math-from-hms a 'rad)) - ((and (not math-simplifying-units) - (memq calc-angle-mode '(deg hms))) + ((memq calc-angle-mode '(deg hms)) (if (or calc-symbolic-mode force-symbolic) (math-div (math-mul a '(var pi var-pi)) 180) (math-mul a (math-pi-over-180)))) (t a))) (defun math-from-radians-2 (a &optional force-symbolic) ; [N N] - (cond ((and (not math-simplifying-units) - (memq calc-angle-mode '(deg hms))) + (cond ((memq calc-angle-mode '(deg hms)) (if (or calc-symbolic-mode force-symbolic) (math-div (math-mul 180 a) '(var pi var-pi)) (math-div a (math-pi-over-180)))) -- 2.11.0 >From b1b6f62f5baa8023a7b5d45b1d30399c8e8f82a2 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Sun, 12 Feb 2017 21:45:47 +0900 Subject: [PATCH 2/2] Prevent from override input angle unit while simplifying Ignore calc-angle-mode while simplifying if the expression contains angle units (Bug#23899). * lisp/calc/calc-alg.el (calc-input-angle-units): New defun. (math-simplify): If TOP-EXPR contains angle units, then bind calc-angle-mode to 'rad. * test/lisp/calc/calc-tests.el (test-calc-23889): New test. --- lisp/calc/calc-alg.el | 9 +++++++++ test/lisp/calc/calc-tests.el | 46 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/lisp/calc/calc-alg.el b/lisp/calc/calc-alg.el index 4e63d238c7..9db901a975 100644 --- a/lisp/calc/calc-alg.el +++ b/lisp/calc/calc-alg.el @@ -355,10 +355,19 @@ math-hyperbolic-trig-rewrite ;; math-simplify-step, which is called by math-simplify. (defvar math-top-only) +(defun calc-input-angle-units (input) + (cond ((math-expr-contains input '(var deg var-deg)) 'deg) + ((math-expr-contains input '(var rad var-rad)) 'rad) + ((math-expr-contains input '(var hms var-hms)) 'hms) + (t nil))) + ;; math-normalize-error is declared in calc.el. (defvar math-normalize-error) (defun math-simplify (top-expr) (let ((math-simplifying t) + (calc-angle-mode (if (calc-input-angle-units top-expr) + 'rad + calc-angle-mode)) (math-top-only (consp calc-simplify-mode)) (simp-rules (append (and (calc-has-rules 'var-AlgSimpRules) '((var AlgSimpRules var-AlgSimpRules))) diff --git a/test/lisp/calc/calc-tests.el b/test/lisp/calc/calc-tests.el index 8f56d48d01..45b735c3c6 100644 --- a/test/lisp/calc/calc-tests.el +++ b/test/lisp/calc/calc-tests.el @@ -86,6 +86,52 @@ calc-tests-simple (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 + (math-simplify-units + '(calcFunc-cos 1)))) + 0 4)))))) + (provide 'calc-tests) ;;; calc-tests.el ends here -- 2.11.0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.7) of 2017-02-12 Repository revision: 862d6438cfa6c6c035033697751f3d002357b024