unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* How is math-round different from other Calc functions?
@ 2022-02-01 21:12 Daniele Nicolodi
  2022-02-02  8:29 ` Andreas Schwab
  2022-02-02  8:34 ` Mattias Engdegård
  0 siblings, 2 replies; 4+ messages in thread
From: Daniele Nicolodi @ 2022-02-01 21:12 UTC (permalink / raw)
  To: Emacs developers

Hello,

it is possible to invoke Calc functions on quantities with units:

(calc-eval "sqrt(4.0 g)")
"2. sqrt(g)"

However, it this does not work for round():

(calc-eval "round(4.0 g)")
"round(4. g)"

Not knowing what is going on, I decided to build my own Calc function 
that does what is required:

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

However, this somehow does not work:

(calc-eval "uround(2.345 g)")
"uround(2.345 g)"

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

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

(calc-eval "uplus(2.345 g)")
"3.345 g"

Why is it so? How do I work around this?

Thank you.

Cheers,
Dan



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-02  8:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-01 21:12 How is math-round different from other Calc functions? Daniele Nicolodi
2022-02-02  8:29 ` Andreas Schwab
2022-02-02  8:34 ` Mattias Engdegård
2022-02-02  8:51   ` Daniele Nicolodi

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).