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

Andrew Barnert abarnert at yahoo.com
Sat Jan 24 06:02:32 CET 2015


On Friday, January 23, 2015 8:22 PM, Chris Barker <chris.barker at noaa.gov> wrote:

>On Fri, Jan 23, 2015 at 6:41 PM, 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.
>
>I could mention it -- though I started all this thinking that we should keep relative and absolute tolerance separate, then realized that relative was going to be useless for zero, so added the absolute tolerance to cover that (which I originally named zero_tol, but realized that it really was absolute everywhere...). Now that we're thinking that we can have a switch for the exactly zero case, then there may be no need to have an absoute tolerance parameter, but only relative and zero.
>
>Then you'd have a separate function (if you wanted) for absolute tolerance, so it could have a default -- that may be better than requiring the user to set the parameter to get an absolute tolerance test at all.
>

>I guess the key question is if someone would want both an relative tolerance and an absolute tolerance, aside from the zero issue.

Which already raises whether they'd want to min, max, average, or sum the two. And frankly I have no idea. That's exactly the question I didn't want to even try to answer, because smarter people than me have already given arguments about this and I don't have anything extra to contribute. But I guess you do have to answer it, since you're writing the PEP. :)


More information about the Python-ideas mailing list