help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (+ 5.1 0.1)


From: Anselm Helbig
Subject: Re: (+ 5.1 0.1)
Date: Mon, 13 Jul 2009 14:21:05 +0200

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]