all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Daniele Nicolodi <daniele@grinta.net>
To: "Mattias Engdegård" <mattiase@acm.org>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: How is math-round different from other Calc functions?
Date: Wed, 2 Feb 2022 09:51:24 +0100	[thread overview]
Message-ID: <cf6e0a1e-47de-248e-f996-fe7c5122bdf0@grinta.net> (raw)
In-Reply-To: <E87D695C-DF7A-419E-A6A7-5E7C0B556859@acm.org>

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	other threads:[~2022-02-02  8:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cf6e0a1e-47de-248e-f996-fe7c5122bdf0@grinta.net \
    --to=daniele@grinta.net \
    --cc=emacs-devel@gnu.org \
    --cc=mattiase@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.