[Python-ideas] PEP 485: A Function for testing approximate equality
Ron Adam
ron3200 at gmail.com
Tue Feb 17 02:11:47 CET 2015
On 02/15/2015 05:07 PM, Neil Girdhar wrote:
> I'm +1 on the idea, +1 on the name, but -1 on symmetry.
>
> I'm glad that you included "other approaches" (what people actually do in
> the field). However, your argument that "is it that hard to just type it
> in" — the whole point of this method is to give a self-commenting line that
> describes what the reader means. Doesn't it make sense to say: is *my
> value* close to *some true value*? If you wanted a symmetric test in
> english, you might say "are these values close to each other"?
My understanding of the main use of the function is to ask if two values
can be considered equivalent within some relative and/or absolute error amount.
About those "is it really hard to write?" comments in the PEP. They refer
to only the absolute comparisons. But they aren't as easy to get right as
most people think. Floating point is hard enough to understand correctly
that only a very few bother to write correct comparisons. ie.. not using
<=. >=. and == in floating point comparisons and adding an appropriate epsilon.
I think at this point what we need is to make sure we have some very good
tests and examples that represent the various different uses in different
circumstances. That may also answer any concerns any one still might have
about the various choices.
Cheers,
Ron
More information about the Python-ideas
mailing list