round() wrong in Python 2.4?

Jeremy Sanders jeremy+complangpython at jeremysanders.net
Wed Sep 14 06:55:41 EDT 2005


Robert Kern wrote:

> That's not what he's asking about. He's asking why his Python 2.3 rounds
> 0.0225 *up* to 0.023 while his Python 2.4 rounds *down* to 0.022. It's
> the change in behavior that he's concerned with and isn't just the usual
> floating point problem.

You can't rely on either being true, given the nature of the inexact
representation of the number, and the fact that python ignores quite a lot
of the IEEE stuff. Different optimisations (particularly with the 80 bit
floating point registers in x86), will lead to different represenations.
Any code which relies on a particular behaviour is broken.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/



More information about the Python-list mailing list