[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#19025: 24.4; precision error when adding two floats
From: |
Jay Belanger |
Subject: |
bug#19025: 24.4; precision error when adding two floats |
Date: |
Tue, 11 Nov 2014 20:28:49 -0600 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
>> (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.