Does python suck or I am just stupid?

Greg Ewing (using news.cis.dfn.de) me at privacy.net
Tue Feb 25 22:15:01 EST 2003


Stefan Quandt wrote:
> To avoid accumulation of small rounding errors while
> successive adding of small float values in loops
> it's preferable to write something like
>  u = i * u_inc
>  i += 1
> instead of
>  u = u + u_inc
> 
> This will make your problem disappear so you can
> stop head banging :)

Not necessarily. The problem remains that 0.001 is
not exactly representable in binary floating point,
so, e.g. 250 * 0.001 still won't be guaranteed to
exactly equal 0.25.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list