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

Andrew Barnert abarnert at yahoo.com
Sat Jan 24 04:32:20 CET 2015


On Jan 23, 2015, at 18:41, Chris Angelico <rosuav at gmail.com> wrote:

> On Sat, Jan 24, 2015 at 1:35 PM, Andrew Barnert
> <abarnert at yahoo.com.dmarc.invalid> wrote:
>> Maybe the answer there is to have an is_close_to_0 function, instead of a parameter that's only useful if expected is 0? But then you might have, say, a comprehension where some of the expected values are 0 and some aren't, so maybe not...
> 
> That's a more philosophical question about API design. It's probably
> worth mentioning the two options in the PEP - separate function for
> "close to zero" with these args, or put it all into the one function
> with those args.

Sure. And obviously the PEP has to pick one of the options and make the case for it.

I just wanted to make it clear that (I'm pretty sure) it really is only 0 that's special here, not "any subnormal" or "small numbers in some vague sense" or anything like that. The problem is that nothing is within even a ridiculously huge relative tolerance of 0 except 0; plenty of things (or at least as many values as you have reason to expect) are within a reasonable tolerance of a nonzero subnormal.

(Also, this is just about zero_tol, not about the wider abs-and-rel issue, which I have nothing to add to.)


More information about the Python-ideas mailing list