[Python-Dev] nice()

Andrew Lentvorski bsder at allcaps.org
Thu Feb 16 11:36:05 CET 2006


Smith wrote:
> Everyone knows that fp numbers must be compared with caution, but
> there is a void in the relative-error department for exercising such
> caution, thus the proposal for something like 'areclose'. The problem
> with areclose(), however, is that it only solves one part of the
> problem that needs to be solved if two fp's *are* going to be
> compared: if you are going to check if a < b you would need to do
> something like
> 
> not areclose(a,b) and a < b

-1

This kind of function, at best, delays the newbie pain of learning about 
  binary floating point very slightly.  No matter how you set your test, 
I can make a pathological case which will catch at the boundary.  The 
standard deviation formula; the area of triangle formula which fails on 
slivers; ill-conditioned linear equations--the examples are endless 
which can trip up newbies.

On the other hand, people who do care about accurate numerical analysis 
will not trust that the people who wrote the library really had enough 
numerical sophistication and will simply rewrite the test *anyhow*.

The "best" solution would be to optimize the Decimal module into 
something sufficiently fast that binary floating point goes away by 
default in Python.

A nice reference about binary floating point is:
"What Every Computer Scientist Should Know About Floating-Point 
Arithmetic" by David Goldberg (available *everywhere*)

For truly pedantic details about the gory nastiness of binary floating 
point, see William Kahan's homepage at Berkeley:
http://www.cs.berkeley.edu/~wkahan/

-a


More information about the Python-Dev mailing list