GNU bug report logs - #19025
24.4; precision error when adding two floats

Previous Next

Package: emacs;

Reported by: "Kevin W. Currey" <kevalier68 <at> hotmail.com>

Date: Wed, 12 Nov 2014 01:25:02 UTC

Severity: normal

Tags: notabug

Found in version 24.4

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Jay Belanger <jay.p.belanger <at> gmail.com>
To: 19025 <at> debbugs.gnu.org
Cc: jay.p.belanger <at> gmail.com
Subject: bug#19025: 24.4; precision error when adding two floats
Date: Tue, 11 Nov 2014 20:28:49 -0600
>> (message "%s" (+ 379.744 57.93))
>>
>> The above prints 437.67400000000004.  Same if I use 57.930, but if I
>> use 57.931 (below) I get the correct answer 437.675.
>>  
>> (message "%s" (+ 379.744 57.931))
>>
>> I was able to work around by using format:
>>  
>> (message "%s" (format "%f" (+ 379.744 57.93)))
>>
>> which prints 437.674000.
>>  
>> FYI, I can replicate the issue with Emacs 21.3.1.
>
> Isn't this an artifact of the nature of floating-point arithmetic, rather than
> an issue with Emacs per se?

Yes, although it probably wouldn't be a bad idea to point out this issue
in the Elisp documentation.





This bug report was last modified 10 years and 196 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.