From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Roland Winkler Newsgroups: gmane.emacs.bugs Subject: bug#15859: 24.3.50; Calc - dimensionless units again Date: Sun, 16 Apr 2023 23:47:23 -0500 Message-ID: <87r0sj8690.fsf@gnu.org> References: <21120.6201.687671.227593@gargle.gargle.HOWL> <87a5zacxb3.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23155"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 15859@debbugs.gnu.org To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Apr 17 06:48:35 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1poGn5-0005pv-L8 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 17 Apr 2023 06:48:35 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1poGmj-0005YH-Vl; Mon, 17 Apr 2023 00:48:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1poGma-0005WX-4K for bug-gnu-emacs@gnu.org; Mon, 17 Apr 2023 00:48:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1poGmY-0003NX-1J for bug-gnu-emacs@gnu.org; Mon, 17 Apr 2023 00:48:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1poGmX-0008Qd-Jd for bug-gnu-emacs@gnu.org; Mon, 17 Apr 2023 00:48:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Roland Winkler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 17 Apr 2023 04:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 15859 X-GNU-PR-Package: emacs Original-Received: via spool by 15859-submit@debbugs.gnu.org id=B15859.168170686032257 (code B ref 15859); Mon, 17 Apr 2023 04:48:01 +0000 Original-Received: (at 15859) by debbugs.gnu.org; 17 Apr 2023 04:47:40 +0000 Original-Received: from localhost ([127.0.0.1]:52883 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1poGmC-0008OA-58 for submit@debbugs.gnu.org; Mon, 17 Apr 2023 00:47:40 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:46070) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1poGmA-0008NU-CN for 15859@debbugs.gnu.org; Mon, 17 Apr 2023 00:47:38 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1poGm4-0003Eg-Hd; Mon, 17 Apr 2023 00:47:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=RE8pu73elQXktGz+GbAg77vZzlE6vFTkqIxzZ1AlCws=; b=d3W5lDswo80Itia8rdsN bOlhGTXSZa71KcuZ6MWrCYkFAaUEVOL85LPanSW2HEJhYkYfaenfUpKyh7r6Xz61VvK+OzlR8s/RA p1ZB/6BLrP2NlnNDIs6KM38Lunzy+bGUlSMbIEl4WVqTQcxWd786jrdQh8L0PslKtOKX2b3A167LS 2ZS35B57VxfnDEZo9ZZsaOXTTtnrEANJ36ZQpOUo9wGdkRSBmvM1BUB2HsCJ3VGcTMdq+BrCWqN8N 3FaRTOiP9wdtTXbC4lALsVCLry0WLAsQIOteswO28bSeuxpnkzteOGx2jpTj3f5OxQNooHLL52YFI 1uvSjkoDbfUJLA==; Original-Received: from [2600:1700:5650:f790::42] (helo=regnitz) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1poGlw-0002GA-33; Mon, 17 Apr 2023 00:47:30 -0400 In-Reply-To: <87a5zacxb3.fsf@web.de> (Michael Heerdegen's message of "Fri, 14 Apr 2023 17:12:32 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:260169 Archived-At: 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"))))))))))