GNU bug report logs - #75861
31.0.50; calc units error

Previous Next

Package: emacs;

Reported by: çağlar girit <cog <at> pelagi.cc>

Date: Sun, 26 Jan 2025 13:15:02 UTC

Severity: normal

Found in version 31.0.50

Fixed in version 31.1

Done: Ulrich Müller <ulm <at> gentoo.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Ulrich Müller <ulm <at> gentoo.org>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: çağlar girit <cog <at> pelagi.cc>, schwab <at> suse.de, eliz <at> gnu.org, 75861 <at> debbugs.gnu.org, Ulrich Müller <ulm <at> gentoo.org>
Subject: bug#75861: 31.0.50; calc units error
Date: Sat, 01 Feb 2025 23:22:41 +0100
[Message part 1 (text/plain, inline)]
>>>>> On Sat, 01 Feb 2025, Michael Heerdegen wrote:

> One simple possibility could be to predefine ln(10) as a math constant
> and refer to it in the unit definition.  I think we did something
> similar in other places, don't recall the reasons.

This isn't even necessary. calc-math.el already defines math-ln-10, so
we could simply use it.

Something like the attached patch might work. However, I've done only
the most rudimentary testing for it.

[0001-Avoid-ln-10-expression-in-calc-units-definition.patch (text/plain, inline)]
From d8c7776f791d2a25ffdd61e95399f967e1998cb5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ulrich=20M=C3=BCller?= <ulm <at> gentoo.org>
Date: Sat, 1 Feb 2025 23:10:53 +0100
Subject: [PATCH] Avoid ln(10) expression in calc units definition

* calc-units.el (math-standard-units): Use new ln10 constant
instead of ln(10) in the decibel definition.
(math-find-base-units-rec): Allow ln10 in expression.
(math-to-standard-rec): Define the ln10 constant.  (Bug#75861)
---
 lisp/calc/calc-units.el | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el
index d2396a9b262..a4aaf2e35a0 100644
--- a/lisp/calc/calc-units.el
+++ b/lisp/calc/calc-units.el
@@ -314,7 +314,7 @@ math-standard-units
 
     ;; Logarithmic units
     ( Np      nil    "*Neper")
-    ( dB      "(ln(10)/20) Np" "decibel"))
+    ( dB      "(ln10/20) Np" "decibel"))
   "List of predefined units for Calc.
 
 Each element is (NAME DEF DESC TEMP-UNIT HUMAN-DEF), where:
@@ -948,10 +948,9 @@ math-find-base-units-rec
 	  ((eq (car expr) '+)
 	   (math-find-base-units-rec (nth 1 expr) pow))
 	  ((eq (car expr) 'var)
-	   (or (eq (nth 1 expr) 'pi)
+	   (or (memq (nth 1 expr) '(pi ln10))
 	       (error "Unknown name %s in defining expression for unit %s"
 		      (nth 1 expr) (car math-fbu-entry))))
-          ((equal expr '(calcFunc-ln 10)))
 	  (t (error "Malformed defining expression for unit %s"
                     (car math-fbu-entry))))))
 
@@ -1055,9 +1054,9 @@ math-to-standard-rec
 						math-unit-prefixes))
 				   expr)))
 	      expr)
-	  (if (eq base 'pi)
-	      (math-pi)
-	    expr)))
+	  (cond ((eq base 'pi) (math-pi))
+		((eq base 'ln10) (math-ln-10))
+		(t expr))))
     (if (or
          (Math-primp expr)
          (and (eq (car-safe expr) 'calcFunc-subscr)
-- 
2.48.1


This bug report was last modified 102 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.