emacs-devel
[Top][All Lists]
Advanced

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

How is math-round different from other Calc functions?


From: Daniele Nicolodi
Subject: How is math-round different from other Calc functions?
Date: Tue, 1 Feb 2022 22:12:55 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.4.0

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



reply via email to

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