From: Anselm Helbig <anselm.helbig+news2009@googlemail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: (+ 5.1 0.1)
Date: Mon, 13 Jul 2009 14:21:05 +0200 [thread overview]
Message-ID: <874otgdb9q.wl%anselm.helbig+news2009@googlemail.com> (raw)
In-Reply-To: <44632093-47cc-4907-bfa0-a3202f51657d@q40g2000prh.googlegroups.com>
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
next prev parent reply other threads:[~2009-07-13 12:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-13 10:57 (+ 5.1 0.1) leonut
2009-07-13 12:21 ` Anselm Helbig [this message]
2009-07-13 12:59 ` Teemu Likonen
2009-07-13 13:31 ` leonut
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=874otgdb9q.wl%anselm.helbig+news2009@googlemail.com \
--to=anselm.helbig+news2009@googlemail.com \
--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.