[Python-ideas] PEP 485: A Function for testing approximate equality (original) (raw)
Chris Barker chris.barker at noaa.gov
Fri Feb 6 01:24:21 CET 2015
- Previous message: [Python-ideas] PEP 485: A Function for testing approximate equality
- Next message: [Python-ideas] PEP 485: A Function for testing approximate equality
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
--
Christopher Barker, Ph.D. Oceanographer
Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150205/f624b54e/attachment.html>
- Previous message: [Python-ideas] PEP 485: A Function for testing approximate equality
- Next message: [Python-ideas] PEP 485: A Function for testing approximate equality
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]