From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 8N4rN8NUhV91VwAA0tVLHw (envelope-from ) for ; Tue, 13 Oct 2020 07:18:27 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id WBPzMsNUhV9KIwAAbx9fmQ (envelope-from ) for ; Tue, 13 Oct 2020 07:18:27 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6A01894053D for ; Tue, 13 Oct 2020 07:18:27 +0000 (UTC) Received: from localhost ([::1]:32880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kSEZm-0003Kv-BA for larch@yhetil.org; Tue, 13 Oct 2020 03:18:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kSEYz-0003KS-11 for emacs-orgmode@gnu.org; Tue, 13 Oct 2020 03:17:37 -0400 Received: from psi-seppmail1.ethz.ch ([129.132.93.141]:45254) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kSEYw-000376-7G for emacs-orgmode@gnu.org; Tue, 13 Oct 2020 03:17:36 -0400 Received: from mailg110.ethz.ch (mailg110.ethz.ch [129.132.162.66]) by psi-seppmail1.ethz.ch (Postfix) with ESMTPS; Tue, 13 Oct 2020 09:10:31 +0200 (CEST) Received: from mailm116.d.ethz.ch (2001:67c:10ec:5602::28) by mailg110.ethz.ch (2001:67c:10ec:5605::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2044.4; Tue, 13 Oct 2020 09:10:17 +0200 Received: from dflt2w (85.0.102.19) by mailm116.d.ethz.ch (2001:67c:10ec:5602::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2044.4; Tue, 13 Oct 2020 09:10:31 +0200 References: <3444a52f-36a7-6e9d-46b9-272dddc7a3ef@grinta.net> <87wo0jttxz.fsf@christianmoe.com> <87sgaj26qq.fsf@christianmoe.com> <87sgajrd93.fsf@ucl.ac.uk> User-agent: mu4e 1.4.1; emacs 26.2 From: Derek Feichtinger To: Eric S Fraga Subject: Re: org-tables with monetary amounts In-Reply-To: <87sgajrd93.fsf@ucl.ac.uk> Date: Tue, 13 Oct 2020 09:10:30 +0200 Message-ID: <87h7qy38k9.fsf@psi.ch> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [85.0.102.19] X-ClientProxiedBy: mailm113.d.ethz.ch (2001:67c:10ec:5602::25) To mailm116.d.ethz.ch (2001:67c:10ec:5602::28) X-TM-SNTS-SMTP: B4BD964C9293C13F780CC475DA26D4DD07A32FB44867CCE9CAC21B21C424CABA2000:8 X-ExSBR-RoutingRule: mailg110:psi.ch; mailg110:psi.ch; mailg110:psi.ch; mailg110:psi.ch; X-SM-outgoing: yes Received-SPF: pass client-ip=129.132.93.141; envelope-from=derek.feichtinger@psi.ch; helo=psi-seppmail1.ethz.ch X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/13 03:10:32 X-ACL-Warn: Detected OS = Windows XP [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emacs-orgmode@gnu.org, Daniele Nicolodi , Christian Moe Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -1.01 X-TUID: IqF6qZSQLtW1 Hi, On Mon, Oct 12 2020, Eric S Fraga wrote: > On Monday, 12 Oct 2020 at 10:22, Christian Moe wrote: >> I think I was thinking about adding mode flags for unit computations, >> like in the imagined example above (`$3=$2+$1;u'), similar to what has >> been done for duration computations. > > This would be very useful, actually. I use embedded calc all the time > with units; being able to use some of the same expressions in a table > would be highly welcome. The functions that one can use in calc formulas can be extended using the 'defmath' lisp command. I paste here from my notes (not about monetary units, but easily adapted): +++++++++++++++++++++++++++++++ Defining a new calc function for unit conversion with defmath #+BEGIN_SRC emacs-lisp (defmath uconv (expr target-units &optional pure) (math-convert-units expr target-units pure)) #+END_SRC #+RESULTS: : calcFunc-uconv | km | ft | |--------+--------------| | 2.5 km | 8202.0997 ft | #+TBLFM: $2=uconv($1, ft) Using the units from the table header (if the 3rd arg is given to uconv, the output is stripped of the unit): | km | ft | |-----+-----------| | 2.5 | 8202.0997 | #+TBLFM: $2 = uconv($1 * @<$1, @<$2, t) The standard calc function usimplify also works for this use case: | km | ft | |-----+-----------| | 2.5 | 8202.0997 | #+TBLFM: $2 = usimplify($1 * @<$1 / @<$2) A lisp equivalent of the above #+begin_src elisp (calc-eval "usimplify(2.5 km / ft)") #+end_src #+RESULTS: : 8202.09973753 Let's define a function that converts to base units #+begin_src elisp (defmath ustd (expr) (math-simplify-units (math-to-standard-units expr nil))) #+end_src #+RESULTS: : calcFunc-ustd | distance | time | speed | std unit speed | speed in ft/s | |----------+--------+-------------+------------------+------------------| | 3 km | 2.5 hr | 1.2 km / hr | 0.33333333 m / s | 1.0936133 ft / s | #+TBLFM: @2$3=$1/$2::@2$4=ustd($3)::@2$5=uconv($-1, ft/s) ++++++++++++++++++++++++++++++++++++ -- Paul Scherrer Institut Dr. Derek Feichtinger Phone: +41 56 310 47 33 Group Head HPC and Emerging Technologies Email: derek.feichtinger@psi.ch Building/Room No. OHSA/D17 Forschungsstrasse 111 CH-5232 Villigen PSI