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

From: çağlar girit <[email-masked]>
Date: Mon, 27 Jan 2025 23:20:51 +0100

I can reproduce the bug as follows:

emacs -Q  ;; without .emacs.d/calc.el file
M-x calc  
d M  ;; calc-mathematica-language
' 10 cm ;; algebraic entry
u s  ;; calc-simplify-units
Error "Unknown name ln in defining expression for unit dB"

In other calc language modes, it seems to work fine although I 
didn't test exhaustively.

The error arises because in calc-mathematica-language, algebraic 
entry of "ln(10)" doesn't yield  the numerical value 
2.30258509299, but rather "10 ln" which means 10 times some 
variable "ln".

The expression "ln(10)" is hardcoded in the units table in 
calc-units.el.  When calc-simplify-units executes, it builds the 
units table and attempts to evaluate "ln(10)" (line 317) when 
deriving the SI equivalent of a dB.  Since "ln(10)" is incorrectly 
evaluated in mathematica language mode, there is an error.

So perhaps there is a bug somewhere in the Mathematica language 
implementation, starting at calc-lang.el line 1816, but difficult 
for me to find.

On 2025-01-27 at 18:37:53, Eli Zaretskii wrote:

>> Cc: [email-masked]
>> Date: Mon, 27 Jan 2025 17:18:20 +0100
>> From:  çağlar girit via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <[email-masked]>
>> 
>> You were right!  The line causing the problem was
>> 
>> (setq calc-language 'math)
>> 
>> Which put calc in Mathematica mode and changed how it 
>> interpreted 
>> math expressions with functions, such as "ln" or "sin".
>
> Thanks for telling us.
>
> Is Calc supposed to signal an error when you type "' 10 cm" in
> Mathematica mode, or is that still some (other) kind of bug?
>
>> I don't know how this line appeared in my .emacs.d/calc.el.
>> 
>> calc's definition of the dB unit includes "ln(10)", and calc 
>> builds the units table before evaluating certain algebraic 
>> expressions.  This resulted in the original error message I 
>> submitted.
>> 
>> My apologies.
>
> No need to apologize, anyone could make a mistake.

-- 
çög