Subject: Re: bug#75861: 31.0.50; calc units error

From: Ulrich Müller <[email-masked]>
Date: Sun, 02 Feb 2025 15:01:03 +0100

>>>>> On Sat, 01 Feb 2025, Ulrich Müller wrote:

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

An autoload for calc-math was missing; updated patch attached.

Please review.

>From 4a812b1da3ded4cf65a6c053a6969dc86c34d719 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ulrich=20M=C3=BCller?= <[email-masked]>
Date: Sat, 1 Feb 2025 23:10:53 +0100
Subject: [PATCH] Avoid ln(10) expression in calc units definition

* lisp/calc/calc-ext.el (calc-init-extensions): Autoload calc-math
for math-ln-10.
* lisp/calc/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-ext.el   |  2 +-
 lisp/calc/calc-units.el | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/lisp/calc/calc-ext.el b/lisp/calc/calc-ext.el
index 4ec96d3ef53..060d352fe66 100644
--- a/lisp/calc/calc-ext.el
+++ b/lisp/calc/calc-ext.el
@@ -877,7 +877,7 @@ calc-init-extensions
 math-arctan2-raw math-cos-raw math-cot-raw math-csc-raw
 math-exp-minus-1-raw math-exp-raw
 math-from-radians math-from-radians-2 math-hypot math-infinite-dir
-math-ln-raw math-nearly-equal math-nearly-equal-float
+math-ln-10 math-ln-raw math-nearly-equal math-nearly-equal-float
 math-nearly-zerop math-nearly-zerop-float math-nth-root
 math-sin-cos-raw math-sin-raw math-sqrt math-sqrt-float math-sqrt-raw
 math-tan-raw math-to-radians math-to-radians-2)
diff --git a/lisp/calc/calc-units.el b/lisp/calc/calc-units.el
index d2396a9b262..54d70bdfd93 100644
--- a/lisp/calc/calc-units.el
+++ b/lisp/calc/calc-units.el
@@ -314,7 +314,8 @@ math-standard-units
 
     ;; Logarithmic units
     ( Np      nil    "*Neper")
-    ( dB      "(ln(10)/20) Np" "decibel"))
+    ( dB      "(ln10/20) Np" "decibel" nil
+              "(ln(10)/20) Np"))
   "List of predefined units for Calc.
 
 Each element is (NAME DEF DESC TEMP-UNIT HUMAN-DEF), where:
@@ -948,10 +949,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 +1055,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