From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Anselm Helbig Newsgroups: gmane.emacs.help Subject: Re: (+ 5.1 0.1) Date: Mon, 13 Jul 2009 14:21:05 +0200 Organization: Freie Universitaet Berlin Message-ID: <874otgdb9q.wl%anselm.helbig+news2009@googlemail.com> References: <44632093-47cc-4907-bfa0-a3202f51657d@q40g2000prh.googlegroups.com> NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1247488850 27518 80.91.229.12 (13 Jul 2009 12:40:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 13 Jul 2009 12:40:50 +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 Jul 13 14:40:42 2009 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 1MQKpl-00028w-8w for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Jul 2009 14:40:41 +0200 Original-Received: from localhost ([127.0.0.1]:53582 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MQKpk-0004TM-0b for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Jul 2009 08:40:40 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 34 Original-X-Trace: news.uni-berlin.de OAXwo5bccmkXgDpaRNn+0QKIKyrvMgFEfLFdMFv6rbhRAnljzvy6S46T+h Cancel-Lock: sha1:UMdnoU2fpVUYYQcq2qaERsEhkiI= In-Reply-To: <44632093-47cc-4907-bfa0-a3202f51657d@q40g2000prh.googlegroups.com> Mail-Followup-To: anselm.helbig+news2009@googlemail.com Original-Xref: news.stanford.edu gnu.emacs.help:170828 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:66025 Archived-At: Hi! > First I used "emacs --no-init-file" to start my emacs-22.3, then I > typed (+ 5.1 0.1) in *scratch* buffer. However, when I evaluated this > expression, I got 5.199999999999999. > Can anyone tell me why did this happen? > I tried (+ 5.0 0.1) and (+ 5.2 0.1) and both gave the answers I had > expected. This is a fundamental problem with floating point numbers, something similar happens in python: Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 5.1 + 0.1 5.1999999999999993 For an explanation why this is so, see e.g. this article: http://www.theregister.co.uk/2006/08/12/floating_point_approximation/ Or, of course, http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems HTH, Anselm -- Anselm Helbig mailto:anselm.helbig+news2009@googlemail.com