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

Paul Moore p.f.moore at gmail.com
Fri Feb 6 14:35:43 CET 2015


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 :-)

FWIW, I'm +0.5 with the PEP. (It lost a 0.5 for no other reason than I
don't actually have a use for the function, so it's mostly theoretical
interest for me).

Paul


More information about the Python-ideas mailing list