From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?Q?Oliver_Ve=C4=8Dern=C3=ADk?= Subject: Re: Spreadsheet calculations (24.3/8.0-pre) Date: Wed, 20 Mar 2013 06:48:03 +0100 Message-ID: <878v5i62r0.fsf@kerstf.org> References: <87li9lm3vj.fsf@kerstf.org> <87sj3rusnn.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:34480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIBsr-0000sM-EQ for emacs-orgmode@gnu.org; Wed, 20 Mar 2013 01:48:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UIBsq-0007p9-5m for emacs-orgmode@gnu.org; Wed, 20 Mar 2013 01:48:21 -0400 Received: from plane.gmane.org ([80.91.229.3]:58795) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIBsp-0007oz-VP for emacs-orgmode@gnu.org; Wed, 20 Mar 2013 01:48:20 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UIBtA-00052X-W3 for emacs-orgmode@gnu.org; Wed, 20 Mar 2013 06:48:40 +0100 Received: from 178.112.56.40.wireless.dyn.drei.com ([178.112.56.40]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 20 Mar 2013 06:48:40 +0100 Received: from ov by 178.112.56.40.wireless.dyn.drei.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 20 Mar 2013 06:48:40 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi Bastien, > #+CONSTANTS is meant to be used only once on the file, not per table. that's how I understood it. > When used several times, `org-table-formula-constants-local' was > defining the same constant several times, which is wrong. I fixed > this. I can confirm this is working now. > Let's take other problems one by one if you have time. Sure. Let's start with following tables and Org-mode version 8.0-pre (release_8.0-pre-144-g855dcf @ /home/ov/p/org-mode/lisp/): #+TITLE: Nutrition Facts #+CONSTANTS: b=100.0 j=4.182 #+TBLNAME: nf | Product | kJ | kcal | |-----------+------+------| | Bread | 1372 | 328 | | Butter | 3054 | 730 | | Marmalade | 926 | 221 | #+TBLFM: $3=$2/$j;%.0f | Product | g | kJ | kcal | |-----------+------+------+------| | Bread | 50.6 | 658 | 157 | | Butter | 11.5 | 150 | 36 | | Marmalade | 19.7 | 256 | 61 | |-----------+------+------+------| | | | 1064 | 254 | #+TBLFM: $3='(* $2 (/ (org-lookup-first $1 '(remote(nf,@I$1..@II$1)) '(remote(nf,@I$2..@II$2))) $b));N%.0f::$4=$3/$j;%.0f::@>$3..$4=vsum(@I..II) I'm reapplying formulas by pressing `C-c C-c' on the hash mark of the format line. The expected results are: | Product | g | kJ | kcal | |-----------+------+------+------| | Bread | 50.6 | 694 | 166 | | Butter | 11.5 | 351 | 84 | | Marmalade | 19.7 | 182 | 44 | |-----------+------+------+------| | | | 1227 | 294 | Let's take this apart: #+BEGIN_SRC emacs-lisp (values (* 50.6 (/ 1372 100.0)) (* 11.5 (/ 3054 100.0)) (* 19.7 (/ 926 100.0))) #+END_SRC #+RESULTS: | 694.2320000000001 | 351.21 | 182.422 | I was bitten myself by setting `b=100', which is an integer and led to the wrong result. But Org-mode still calculates as if `b' were an integer. But even replacing `$b' with `100.0' still gives wrong results (second and third line): | Product | g | kJ | kcal | |-----------+------+------+------| | Bread | 50.6 | 694 | 166 | | Butter | 11.5 | 158 | 38 | | Marmalade | 19.7 | 270 | 65 | |-----------+------+------+------| | | | 1122 | 269 | #+TBLFM: $3='(* $2 (/ (org-lookup-first $1 '(remote(nf,@I$1..@II$1)) '(remote(nf,@I$2..@II$2))) 100.0));N%.0f::$4=$3/$j;%.0f::@>$3..$4=vsum(@I..II) -- Oliver