emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Oliver Večerník" <ov@vecernik.at>
To: emacs-orgmode@gnu.org
Subject: Spreadsheet calculations (24.3/8.0-pre)
Date: Mon, 18 Mar 2013 10:52:32 +0100	[thread overview]
Message-ID: <87li9lm3vj.fsf@kerstf.org> (raw)

Hi,

I'm trying to do some simple calculations, but the results are plain
wrong.  I started the minimal example with `emacs -Q -l minimal.emacs
org/minimal.org'.  My Emacs is 24.3 with Org-mode version 8.0-pre
(release_8.0-pre-116-g65cde8 @ /home/ov/p/org-mode/lisp/):

#+TITLE: Nutrition Facts
#+CONSTANTS: b=100 j=4.182

#+TBLNAME: nf
| Product   |   kJ | kcal |
|-----------+------+------|
| Bread     | 1372 |  328 |
| Butter    | 3054 |  730 |
| Marmalade |  926 |  221 |
#+TBLFM: $3=$2/$j;%.0f

Here are some calculations per portion (plain wrong):

| 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))) 100));N%.0f::$4=$3/$j;%.0f::@>$3..$4=vsum(@I..II)

Expected:

| Product   |    g |   kJ | kcal |
|-----------+------+------+------|
| Bread     | 50.6 |  694 |  166 |
| Butter    | 11.5 |  351 |   84 |
| Marmalade | 19.7 |  182 |   44 |
|-----------+------+------+------|
|           |      | 1227 |  294 |
#+TBLFM: $4=$3/$j;%.0f::@>$3..$4=vsum(@I..II)

Using the constant b is also totally wrong:

| Product   |    g | kJ | kcal |
|-----------+------+----+------|
| Bread     | 50.6 |  0 |    0 |
| Butter    | 11.5 |  0 |    0 |
| Marmalade | 19.7 |  0 |    0 |
|-----------+------+----+------|
|           |      |  0 |    0 |
#+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)

These results are achieved using `C-c C-c' on the first column of the
format line.  If I use `C-u C-c C-c' in the tabel I get different
results *every* time.  E.g. pressing `C-u C-c C-c' three times on the
`B' of `Bread':

| Product   |    g |     kJ |  kcal |
|-----------+------+--------+-------|
| Bread     | 50.6 |  32606 |  7784 |
| Butter    | 11.5 |  59888 | 14297 |
| Marmalade | 19.7 | 110192 | 26306 |
|-----------+------+--------+-------|
|           |      | 202686 | 48387 |
#+TBLFM: $3='(* $2 (/ (org-lookup-first $1 '(remote(nf,@I$1..@II$1)) '(remote(nf,@I$2..@II$2))) 100));N%.0f::$4=$3/$j;%.0f::@>$3..$4=vsum(@I..II)

If I go to the end of the format line and press `C-c C-c' I get totally
different results as at the beginning:

| Product   |    g | 1064 |  254 |
|-----------+------+------+------|
| Bread     | 50.6 | 1064 |  254 |
| Butter    | 11.5 | 1470 |  351 |
| Marmalade | 19.7 | 2790 |  666 |
|-----------+------+------+------|
|           |      | 5324 | 1271 |
#+TBLFM: $3='(* $2 (/ (org-lookup-first $1 '(remote(nf,@I$1..@II$1)) '(remote(nf,@I$2..@II$2))) 100));N%.0f::$4=$3/$j;%.0f::@>$3..$4=vsum(@I..II)

If I use `M-x org-table-recalculate-buffer-tables' even the headlines
get screwed up.  Am I doing something wrong or are there severe problems
in the spreadsheet mode?

Thanks in advance!

-- 
Regards, Oliver

             reply	other threads:[~2013-03-18 10:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-18  9:52 Oliver Večerník [this message]
2013-03-18 15:03 ` Spreadsheet calculations (24.3/8.0-pre) Christopher Allan Webber
2013-03-19 14:27 ` Bastien
2013-03-20  5:48   ` Oliver Večerník
2013-04-07  9:53     ` Ippei FURUHASHI
2013-04-08 14:14       ` Oliver Večerník
2013-04-18 14:13         ` Bastien

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=87li9lm3vj.fsf@kerstf.org \
    --to=ov@vecernik.at \
    --cc=emacs-orgmode@gnu.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 public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).