* adding up decimal fractions in the spreadsheet @ 2008-09-27 7:19 Rainer Thiel 2008-09-27 12:19 ` Carsten Dominik 2008-09-27 13:21 ` Manish 0 siblings, 2 replies; 7+ messages in thread From: Rainer Thiel @ 2008-09-27 7:19 UTC (permalink / raw) To: emacs-orgmode Following a hint by Bernt Hansen, I have now changed org-table-sum to (format "%s" res) until I'll be able to use the corrected version Carsten Dominik uploaded to the git repository (which I am not sure how to access). Even so, org-table-sum at times shows a strange behaviour. When I try to sum up the following table: | 12130.68 | | -1444.19 | | -12744.90 | | -186.00 | | 7000.00 | | -7056.00 | | -335.58 | | -277.00 | I get -2912.9899999999993 (-2912.99 being the exact result). This is something I'd expect when square roots or logarithms are implied, but with such a simple addition and subtraction of decimal numbers I'd be inclined to call it a bug. Is there a way to improve org-mode in this respect? Many thanks again for this great mode -- Prof. Dr. Rainer Thiel Institut für Altertumswissenschaften 07737 Jena, Germany (EU) r.thiel@uni-jena.de ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: adding up decimal fractions in the spreadsheet 2008-09-27 7:19 adding up decimal fractions in the spreadsheet Rainer Thiel @ 2008-09-27 12:19 ` Carsten Dominik [not found] ` <d6b6c7740809270606p679feb82n6fbe5f4d582ebcfa@mail.gmail.com> 2008-09-27 13:21 ` Manish 1 sibling, 1 reply; 7+ messages in thread From: Carsten Dominik @ 2008-09-27 12:19 UTC (permalink / raw) To: r.thiel; +Cc: emacs-orgmode Hi Rainer, it is a common mis-conception that a number that has a limited number of digits in base 10 can be represented exactly on a computer. This is correct for integers, but not for fractional numbers. Example: 1. Open the emacs calc with M-x calc RET 2. Type 12130.68 (first number from your example) 3. Press `p 200 RET' to switch to 200 digit precision. 4. press `d r 2 RET' o display the number in Base 2. You'll see 10111101100010.1010111000010100011110101110000101000111101011100001010001111010111000010100011110101110000101000111101011100001010001111010111000010100011110101110000 ................ It works the other way round as well, for example 0.33333333............. has an exact representation in base 3 (0.1). This means that even simple additions like this do produce small errors on computers, and the displayed result will depend upon how he conversion is done. (format "%s" x) just spits out digits, as many as possible. That is why the fix I have pushed to the git repo uses (number-to-string res) and not (format "%s" res) number-to-string is an internal function that tries very hard to do the conversion in the way you intend it. - Carsten On Sep 27, 2008, at 9:19 AM, Rainer Thiel wrote: > Following a hint by Bernt Hansen, I have now changed org-table-sum to > (format "%s" res) until I'll be able to use the corrected version > Carsten Dominik uploaded to the git repository (which I am not sure > how to access). > > Even so, org-table-sum at times shows a strange behaviour. > > When I try to sum up the following table: > > | 12130.68 | > | -1444.19 | > | -12744.90 | > | -186.00 | > | 7000.00 | > | -7056.00 | > | -335.58 | > | -277.00 | > > I get -2912.9899999999993 (-2912.99 being the exact result). This is > something I'd expect when square roots or logarithms are implied, but > with such a simple addition and subtraction of decimal numbers I'd be > inclined to call it a bug. Is there a way to improve org-mode in this > respect? > > Many thanks again for this great mode > -- > Prof. Dr. Rainer Thiel > Institut für Altertumswissenschaften > 07737 Jena, Germany (EU) > r.thiel@uni-jena.de > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <d6b6c7740809270606p679feb82n6fbe5f4d582ebcfa@mail.gmail.com>]
[parent not found: <B1260157-B3E5-4704-8739-F4718BDFCAEC@uva.nl>]
* Re: adding up decimal fractions in the spreadsheet [not found] ` <B1260157-B3E5-4704-8739-F4718BDFCAEC@uva.nl> @ 2008-09-27 14:20 ` Rainer Thiel 2008-09-27 17:59 ` Carsten Dominik 0 siblings, 1 reply; 7+ messages in thread From: Rainer Thiel @ 2008-09-27 14:20 UTC (permalink / raw) To: Carsten Dominik, emacs-orgmode Hi Carsten, 2008/9/27 Carsten Dominik <dominik@uva.nl>: > The other thing you can do is to use your own format to convert the number. > Maybe something like "%.2f" will work for you? Hard to make this correct > for the general case though. Yes, this is not a way to go, as far as I can see, for exactly that reason. Interestingly, | 12130.68 | | -1444.19 | | -12744.90 | | -186.00 | | 7000.00 | | -7056.00 | | -335.58 | | -277.00 | | -2912.99 | #+TBLFM: @9$1=@1$1+@2$1+@3$1+@4$1+@5$1+@6$1+@7$1+@8$1 gives the correct value, there's no need to add `;f2' at the end of the last line. This in itself is a way to go, of course, but would be more comfortable to have a way to sum up all rows but the last one (without having to keep track of the number of rows) or at least to work with ranges, which as far as I have seen so far seems not to be possible in this case. These are minutiae, of course. org-mode is already excellent, and since I discovered it a few weeks ago, I've been making use of it at all times. Many thanks again, Rainer -- Prof. Dr. Rainer Thiel Institut für Altertumswissenschaften 07737 Jena, Germany (EU) r.thiel@uni-jena.de ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: adding up decimal fractions in the spreadsheet 2008-09-27 14:20 ` Rainer Thiel @ 2008-09-27 17:59 ` Carsten Dominik 0 siblings, 0 replies; 7+ messages in thread From: Carsten Dominik @ 2008-09-27 17:59 UTC (permalink / raw) To: r.thiel; +Cc: emacs-orgmode Hi Rainer, On Sep 27, 2008, at 4:20 PM, Rainer Thiel wrote: > Hi Carsten, > > 2008/9/27 Carsten Dominik <dominik@uva.nl>: >> The other thing you can do is to use your own format to convert the >> number. >> Maybe something like "%.2f" will work for you? Hard to make this >> correct >> for the general case though. > > Yes, this is not a way to go, as far as I can see, for exactly that > reason. I agree. > > > Interestingly, > > | 12130.68 | > | -1444.19 | > | -12744.90 | > | -186.00 | > | 7000.00 | > | -7056.00 | > | -335.58 | > | -277.00 | > | -2912.99 | > #+TBLFM: @9$1=@1$1+@2$1+@3$1+@4$1+@5$1+@6$1+@7$1+@8$1 > > gives the correct value, there's no need to add `;f2' at the end of > the last line. Yes, calc has its own rules for formatting numbers > This in itself is a way to go, of course, but would be > more comfortable to have a way to sum up all rows but the last one > (without having to keep track of the number of rows) or at least to > work with ranges, which as far as I have seen so far seems not to be > possible in this case. Check out the manual section about the spreadsheet, and the corresponding tutorial on worg. A lot can be done with that, and there are ranges between row numbers or between horizontal lines. In your example: | 12130.68 | | -1444.19 | | -12744.90 | | -186.00 | | 7000.00 | | -7056.00 | | -335.58 | | -277.00 | | -2912.99 | #+TBLFM: @9$1=vsum(@1..@8) Or much better: |-----------| | 12130.68 | | -1444.19 | | -12744.90 | | -186.00 | | 7000.00 | | -7056.00 | | -335.58 | | -277.00 | |-----------| | -2912.99 | #+TBLFM: @9$1=vsum(@I..@II) Add new line with M-S-down, so that the absolute reference to the last row will automatically be shifted. org-table-sum is an old hack, from before the existence of the spreadsheet functions. I still use I, but only occasionally, not for anything I need to change and recompute. > > > These are minutiae, of course. org-mode is already excellent, and > since I discovered it a few weeks ago, I've been making use of it at > all times. Good to know. - Carsten ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: adding up decimal fractions in the spreadsheet 2008-09-27 7:19 adding up decimal fractions in the spreadsheet Rainer Thiel 2008-09-27 12:19 ` Carsten Dominik @ 2008-09-27 13:21 ` Manish 2008-09-27 13:29 ` Rainer Thiel 1 sibling, 1 reply; 7+ messages in thread From: Manish @ 2008-09-27 13:21 UTC (permalink / raw) To: r.thiel; +Cc: emacs-orgmode On Sat, Sep 27, 2008 at 12:49 PM, Rainer Thiel <wrote: > Following a hint by Bernt Hansen, I have now changed org-table-sum to > (format "%s" res) until I'll be able to use the corrected version > Carsten Dominik uploaded to the git repository (which I am not sure > how to access). About not being sure how to access latest Org, FAQ at http://orgmode.org/worg/org-faq.php might help. -- Manish ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: adding up decimal fractions in the spreadsheet 2008-09-27 13:21 ` Manish @ 2008-09-27 13:29 ` Rainer Thiel 2008-09-29 2:46 ` Manish 0 siblings, 1 reply; 7+ messages in thread From: Rainer Thiel @ 2008-09-27 13:29 UTC (permalink / raw) To: Manish, emacs-orgmode 2008/9/27 Manish <mailtomanish.sharma@gmail.com>: > About not being sure how to access latest Org, FAQ at > http://orgmode.org/worg/org-faq.php might help. Thank you, Manish. Is this lykely to work on a Windows machine with cygwin installed, too? Best wishes, and many thanks again, Rainer -- Prof. Dr. Rainer Thiel Institut für Altertumswissenschaften 07737 Jena, Germany (EU) r.thiel@uni-jena.de ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: adding up decimal fractions in the spreadsheet 2008-09-27 13:29 ` Rainer Thiel @ 2008-09-29 2:46 ` Manish 0 siblings, 0 replies; 7+ messages in thread From: Manish @ 2008-09-29 2:46 UTC (permalink / raw) To: r.thiel; +Cc: emacs-orgmode On Sat, Sep 27, 2008 at 6:59 PM, Rainer Thiel wrote: > 2008/9/27 Manish : >> About not being sure how to access latest Org, FAQ at >> http://orgmode.org/worg/org-faq.php might help. > > Thank you, Manish. Is this lykely to work on a Windows machine with > cygwin installed, too? Yes, I use this on Cygwin. I just do not do `make install' and add `~/elisp/org-mode.git/lisp' and `~/elisp/org-mode.git/contrib/lisp' to the load path (for ~ to work I have HOME defined in Windows user environment variables.) Updating Org then boils down to: git pull && make clean && make && make doc. HTH, -- Manish ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-09-29 2:46 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-09-27 7:19 adding up decimal fractions in the spreadsheet Rainer Thiel 2008-09-27 12:19 ` Carsten Dominik [not found] ` <d6b6c7740809270606p679feb82n6fbe5f4d582ebcfa@mail.gmail.com> [not found] ` <B1260157-B3E5-4704-8739-F4718BDFCAEC@uva.nl> 2008-09-27 14:20 ` Rainer Thiel 2008-09-27 17:59 ` Carsten Dominik 2008-09-27 13:21 ` Manish 2008-09-27 13:29 ` Rainer Thiel 2008-09-29 2:46 ` Manish
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.