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


Message #10 received at control <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: "Kevin W. Currey" <kevalier68 <at> hotmail.com>
Cc: 19025-done <at> debbugs.gnu.org
Subject: Re: bug#19025: 24.4; precision error when adding two floats
Date: Tue, 11 Nov 2014 21:06:35 -0500
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




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

Previous Next


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