unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Roland Winkler <winkler@gnu.org>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: 15859@debbugs.gnu.org
Subject: bug#15859: 24.3.50; Calc - dimensionless units again
Date: Sun, 16 Apr 2023 23:47:23 -0500	[thread overview]
Message-ID: <87r0sj8690.fsf@gnu.org> (raw)
In-Reply-To: <87a5zacxb3.fsf@web.de> (Michael Heerdegen's message of "Fri, 14 Apr 2023 17:12:32 +0200")

On Fri, Apr 14 2023, Michael Heerdegen wrote:
> At least the result given by Calc is not incorrect.  It would be better
> if it would respect the units explicitly requested by the user, though.

The command `calc-convert-units' from the old calc tar ball (from before
calc became part of GNU Emacs) had been doing for me exactly what I
expected for the longest time.  The trouble only started for me when the
old code got modified.  Therefore, some time ago I grabbed the old code
of `calc-convert-units' and put it into my emacs init file.  (In the
code attached below I merely added a let-binding for the internal
variable UNITS.)  This code has been working fine for me since then with
recent versions of GNU Emacs and the likewise more recent versions of
calc they ship with.  (I use this command on a regular basis.)

I suggest to revert the changes of the command `calc-convert-units' and
go back to its old definition.


(defun calc-convert-units (&optional old-units new-units)
  (interactive)
  (calc-slow-wrapper
   (let ((expr (calc-top-n 1))
	 uoldname unew units)
     (or (math-units-in-expr-p expr t)
	 (let ((uold (or old-units
			 (progn
			   (setq uoldname (read-string "Old units: "))
			   (if (equal uoldname "")
			       (progn
				 (setq uoldname "1")
				 1)
			     (if (string-match "\\` */" uoldname)
				 (setq uoldname (concat "1" uoldname)))
			     (math-read-expr uoldname))))))
	   (if (eq (car-safe uold) 'error)
	       (error "Bad format in units expression: %s" (nth 1 uold)))
	   (setq expr (math-mul expr uold))))
     (or new-units
	 (setq new-units (read-string (if uoldname
					  (concat "Old units: "
						  uoldname
						  ", new units: ")
					"New units: "))))
     (if (string-match "\\` */" new-units)
	 (setq new-units (concat "1" new-units)))
     (setq units (math-read-expr new-units))
     (if (eq (car-safe units) 'error)
	 (error "Bad format in units expression: %s" (nth 2 units)))
     (let ((unew (math-units-in-expr-p units t))
	   (std (and (eq (car-safe units) 'var)
		     (assq (nth 1 units) math-standard-units-systems))))
       (if std
	   (calc-enter-result 1 "cvun" (math-simplify-units
					(math-to-standard-units expr
								(nth 1 std))))
	 (or unew
	     (error "No units specified"))
	 (calc-enter-result 1 "cvun"
			    (math-convert-units
			     expr units
			     (and uoldname (not (equal uoldname "1"))))))))))





  reply	other threads:[~2023-04-17  4:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-10 23:35 bug#15859: 24.3.50; Calc - dimensionless units again Roland Winkler
2020-11-22 15:13 ` Michael Heerdegen
2020-11-23 15:13   ` Roland Winkler
2020-11-24  1:00     ` Michael Heerdegen
2020-11-24 23:37       ` Michael Heerdegen
2021-09-06  9:40         ` Lars Ingebrigtsen
2021-09-17  1:45           ` Michael Heerdegen
2023-04-14 15:12 ` Michael Heerdegen
2023-04-17  4:47   ` Roland Winkler [this message]
2023-04-17 14:04     ` Michael Heerdegen
2023-04-17 15:20       ` Roland Winkler
2023-04-18 23:07         ` Michael Heerdegen
2023-04-25  3:44           ` Roland Winkler
2023-04-21 14:25 ` Michael Heerdegen
2023-04-25  3:44   ` Roland Winkler

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87r0sj8690.fsf@gnu.org \
    --to=winkler@gnu.org \
    --cc=15859@debbugs.gnu.org \
    --cc=michael_heerdegen@web.de \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).