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

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

bug#19025: 24.4; precision error when adding two floats


From: Stefan Monnier
Subject: bug#19025: 24.4; precision error when adding two floats
Date: Tue, 11 Nov 2014 21:06:35 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

tags 19025 notabug
thanks

> (message "%s" (+ 379.744 57.93))
> The above prints 437.67400000000004.

That's the difference between floating-point numbers and real or
rational numbers.

> (message "%s" (format "%f" (+ 379.744 57.93)))

You can cut the middle man: (message "%f" (+ 379.744 57.93))

But note that this prints something "incorrect":

     M-: (message "%f" (+ 379.744 57.93))
     => 437.674000.
     M-: (equal (+ 379.744 57.93) 437.674000)
     => nil

It's just that %f rounds differently.



        Stefan





reply via email to

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