[Python-ideas] PEP 485: A Function for testing approximate equality

Antoine Pitrou solipsis at pitrou.net
Fri Feb 6 13:28:52 CET 2015


Ok, more simply then: does is_close_to(0.0, 0.0) return True?



On Thu, 5 Feb 2015 16:24:21 -0800
Chris Barker <chris.barker at noaa.gov> wrote:
> On Thu, Feb 5, 2015 at 3:04 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> 
> 
> > I think it is a nuisance that this PEP doesn't work at zero by default.
> >
> 
> I think this is the biggest point of contention -- it' s a hard problem.
> 
> If this is meant to ease the life of non-specialist users then it
> > should do the right thing out of the box, IMO.
> >
> 
> That's the trick -- there simply IS NO "right thing" to be done out of the
> box. A relative comparison to zero is mathematically and computationally
> impossible -- you need an absolute comparison. And to set a default for
> that you need to know the general magnitude of the values your user is
> going to have -- and we can't know that.
> 
> If we really believe that almost all people will be working with numbers of
> around a magnitude of 1, then we could set a default -- by why in the world
> are you using floating point numbers with a range of about 1e-300 to 1e300
> in that case?
> 
> NOTE: numpy.allclose() uses an absolute tolerance default of 1e-08 -- so
> someone thought that was a good idea. But as I've been thinking about all
> this, I decided it was very dangerous. In fact, I just did a quick grep of
> the unit tests in my current code base: 159 uses of allclose, and almost
> none with an absolute tolerance specified -- now I need to go and check
> those, most of them probably need a more carefully thought out value.
> 
> I'm (and my team) are just one careless programmer, I guess, but I don't
> think I'm the only one that tends to use defaults, and only go back and
> think about if a test fails. And as you say, the "non-specialist users" are
> the most likely to be careless.
> 
> -Chris
> 
> 
> 
> 





More information about the Python-ideas mailing list