emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How is math-round different from other Calc functions?


From: Daniele Nicolodi
Subject: Re: How is math-round different from other Calc functions?
Date: Wed, 2 Feb 2022 09:51:24 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.4.0

On 02/02/2022 09:34, Mattias EngdegÄrd wrote:
1 feb. 2022 kl. 22.12 skrev Daniele Nicolodi <daniele@grinta.net>:

(defmath uround (x)
  (* (round (remove-units x)) (extract-units x)))

Looks like you may need to do `math-simplify` after `remove-units`, since 
`math-round` only works if its argument is a value, not an unsimplified 
expression such as `(* (float 4 0) 1)`.

but it does if I replace round() with any other function:

(defmath uplus (x)
  (* (1+ (remove-units x)) (calc-eval "kg" 'raw)))

That `(1+ ...)` becomes `(math-add ... x)` and presumably `math-add` makes an 
effort to simplify its arguments for other reasons.

At least, this is from a cursory look at the code. Does that make sense?

Yes, that's it. Adding `usimplify()` I don't need to define a function that explicitly deals with the units:

(calc-eval "usimplify(round(2.234 g))")
"2 g"

Thank you.

Cheers,
Dan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]