From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sven Joachim Newsgroups: gmane.emacs.help Subject: Re: calculation error with built-in command CTRL + J?! Date: Mon, 14 Apr 2008 08:40:13 +0200 Message-ID: <87tzi5hrci.fsf@gmx.de> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1208158862 21154 80.91.229.12 (14 Apr 2008 07:41:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 14 Apr 2008 07:41:02 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Apr 14 09:41:31 2008 connect(): Connection refused Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JlJJa-0001Uv-Df for geh-help-gnu-emacs@m.gmane.org; Mon, 14 Apr 2008 09:41:22 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JlJIw-0006Zo-7w for geh-help-gnu-emacs@m.gmane.org; Mon, 14 Apr 2008 03:40:42 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!goblin1!goblin.stu.neva.ru!uio.no!quimby.gnus.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 43 Original-NNTP-Posting-Host: p54866793.dip.t-dialin.net Original-X-Trace: quimby.gnus.org 1208155358 29980 84.134.103.147 (14 Apr 2008 06:42:38 GMT) Original-X-Complaints-To: usenet@quimby.gnus.org Original-NNTP-Posting-Date: Mon, 14 Apr 2008 06:42:38 +0000 (UTC) User-Agent: Gnus/5.110008 (No Gnus v0.8) Emacs/22.2.50 (gnu/linux) Cancel-Lock: sha1:AebizH124gFMZs3OXUTPXByCUqo= Original-Xref: shelby.stanford.edu gnu.emacs.help:157909 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:53276 Archived-At: 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 int main(void) { printf("12 * 2.6 = %.15f\n", 12 * 2.6); return 0; } --8<---------------cut here---------------end--------------->8--- Regards, Sven