all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: 23889@debbugs.gnu.org
Subject: bug#23889: 25.0.95; Calc; calc-simplify-units not working as documented for trigometric functions
Date: Mon, 4 Jul 2016 17:18:52 +0900 (JST)	[thread overview]
Message-ID: <alpine.DEB.2.20.1607041716510.7718@calancha-pc> (raw)
In-Reply-To: <87k2h2odo2.fsf@duenenhof-wilhelm.de>

[-- Attachment #1: Type: text/plain, Size: 4124 bytes --]

Thanks for the report.

From the documentation:

"(‘calc-simplify-units’) command will simplify ‘sin(45 deg)’ by taking
the sine of 45 degrees, regardless of the current angular mode."

The problem is that ‘calc-simplify-units’ is actually checking the value
of 'calc-angle-mode'.

There is an internal variable 'math-simplifying-units'; 
'match-simplify-units' bind this var to a non-nil value
while performing its task.

Following patch use 'math-simplifying-units' to prevent that
'calc-simplify-units' use the value of 'calc-angle-mode'.

Regards,
Tino

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

From 96b92d9793bd035a4f0ed79a4e434418b0253608 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Mon, 4 Jul 2016 16:32:27 +0900
Subject: [PATCH] Ignore angle mode when simplifying units

* lisp/calc/calc-forms.el (math-to-hms, math-from-hms):
Ignore value of 'calc-angle-mode' when 'math-simplifying-units'
evaluates non-nil (Bug#23889).

* lisp/calc/calc-math.el (math-to-radians)
(math-from-radians-2, math-to-radians-2): Idem.
---
  lisp/calc/calc-forms.el | 12 +++++++++---
  lisp/calc/calc-math.el  |  9 +++++----
  2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/lisp/calc/calc-forms.el b/lisp/calc/calc-forms.el
index c94b89d..153b904 100644
--- a/lisp/calc/calc-forms.el
+++ b/lisp/calc/calc-forms.el
@@ -317,7 +317,9 @@ math-to-hms
  	 (list 'calcFunc-hms a))
  	((math-negp a)
  	 (math-neg (math-to-hms (math-neg a) ang)))
-	((eq (or ang calc-angle-mode) 'rad)
+	((eq (or ang
+                 (and (not math-simplifying-units) calc-angle-mode))
+                 'rad)
  	 (math-to-hms (math-div a (math-pi-over-180)) 'deg))
  	((memq (car-safe a) '(cplx polar)) a)
  	(t
@@ -354,12 +356,16 @@ 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 calc-angle-mode) 'rad)
+	     (if (eq (or ang
+                         (and (not math-simplifying-units) 
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 calc-angle-mode) 'rad)
+	((eq (or ang
+                 (and (not math-simplifying-units) 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 699ef6f..d35460e 100644
--- a/lisp/calc/calc-math.el
+++ b/lisp/calc/calc-math.el
@@ -763,12 +763,13 @@ calcFunc-nroot
  (defun math-to-radians (a)   ; [N N]
    (cond ((eq (car-safe a) 'hms)
  	 (math-from-hms a 'rad))
-	((memq calc-angle-mode '(deg hms))
+	((and (not math-simplifying-units)
+              (memq calc-angle-mode '(deg hms)))
  	 (math-mul a (math-pi-over-180)))
  	(t a)))

  (defun math-from-radians (a)   ; [N N]
-  (cond ((eq calc-angle-mode 'deg)
+  (cond ((and (not math-simplifying-units) (eq calc-angle-mode 'deg))
  	 (if (math-constp a)
  	     (math-div a (math-pi-over-180))
  	   (list 'calcFunc-deg a)))
@@ -779,14 +780,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))
-	((memq calc-angle-mode '(deg hms))
+	((and (not math-simplifying-units) (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 ((memq calc-angle-mode '(deg hms))
+  (cond ((and (not math-simplifying-units) (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.8.1


In GNU Emacs 25.1.50.5 (x86_64-pc-linux-gnu, GTK+ Version 3.20.6)
  of 2016-07-04
Repository revision: 05d76dba6604f78e4b2b7b9f8b30c916cad7d32a

  reply	other threads:[~2016-07-04  8:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-03 17:05 bug#23889: 25.0.95; Calc; calc-simplify-units not working as documented for trigometric functions H. Dieter Wilhelm
2016-07-04  8:18 ` Tino Calancha [this message]
2016-07-11 15:41 ` bug#23889: (no subject) Tino Calancha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1607041716510.7718@calancha-pc \
    --to=tino.calancha@gmail.com \
    --cc=23889@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.