From: Sven Joachim <svenjoac@gmx.de>
To: help-gnu-emacs@gnu.org
Subject: Re: calculation error with built-in command CTRL + J?!
Date: Mon, 14 Apr 2008 08:40:13 +0200 [thread overview]
Message-ID: <87tzi5hrci.fsf@gmx.de> (raw)
In-Reply-To: ftukqh$tbi$1@news4.fe.internet.bosch.com
On 2008-04-14 05:59 +0200, Andreas Borde wrote:
> I calculated
> (* 12 2.6) with the built in command CTRL + J and got
> 31.200000000000003
A normal rounding error for floating point numbers.
> It is the same for
> (* 2.6 12)
Multiplication is commutative. ;-)
> I am wondering about the tailing numbers after 31.2!
The computer can only represent real numbers that are a linear
combination of (possibly negative) powers of 2, all other numbers can
only be approximated. See http://en.wikipedia.org/wiki/Floating_point
for details.
> If I calculate (* 2.5 12) then the result is the expected 30.0.
Because 2.5 = 2^1 + 2^(-1), therefore the computer can calculate exactly.
> Can someone tell me the reason? Is there something wrong with
> my calcuation?
No, there's nothing wrong. The following little C program prints the
same results as Emacs:
--8<---------------cut here---------------start------------->8---
#include <stdio.h>
int main(void)
{
printf("12 * 2.6 = %.15f\n", 12 * 2.6);
return 0;
}
--8<---------------cut here---------------end--------------->8---
Regards,
Sven
prev parent reply other threads:[~2008-04-14 6:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-14 3:59 calculation error with built-in command CTRL + J?! Borde, Andreas
2008-04-14 6:11 ` David Hansen
2008-04-14 6:24 ` Thierry Volpiatto
2008-04-14 6:40 ` Sven Joachim [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=87tzi5hrci.fsf@gmx.de \
--to=svenjoac@gmx.de \
--cc=help-gnu-emacs@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 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.