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

David Mertz mertz at gnosis.cx
Sat Feb 7 21:56:45 CET 2015


+1 on PEP 485 as currently written.

Maybe it's not perfect in every edge case, but per Nick's standard, it is
significantly "less wrong" than 'a == b'.

On Fri, Feb 6, 2015 at 5:48 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> On 6 February 2015 at 23:35, Paul Moore <p.f.moore at gmail.com> wrote:
> > On 6 February 2015 at 12:28, Antoine Pitrou <solipsis at pitrou.net> wrote:
> >> Ok, more simply then: does is_close_to(0.0, 0.0) return True?
> >
> > From the formula in the PEP
> >
> >    """abs(a-b) <= max( rel_tolerance * min(abs(a), abs(b), abs_tolerance
> )"""
> >
> > yes it does. More generally, is_close_to(x, x) is always true. That's
> > a key requirement - that "closeness" includes equality.
> >
> > I think the "weirdness" around zero is simply that there's no x for
> > which is_close_to(x, 0) and x != 0. Which TBH isn't really all that
> > weird :-)
>
> Right, by default it degrades to exact equality when one of the
> operands is zero, just as it will degrade to exact equality when the
> relative tolerance is set to zero. This should probably be stated
> explicitly in the PEP, since it isn't immediately obvious from the
> formal definition.
>
> +1 on the PEP from me - it meets the goal I suggested of being clearly
> better for comparing floating point values than standard equality, and
> manages to hide most of the surprising complexity of floating point
> comparisons.
>
> Regards,
> Nick.
>
> --
> Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150207/cb59cc71/attachment.html>


More information about the Python-ideas mailing list