[Python-ideas] Floating point "closeness" Proposal Outline

Paul Moore p.f.moore at gmail.com
Tue Jan 20 10:36:19 CET 2015


On 20 January 2015 at 04:10, Neil Girdhar <mistersheik at gmail.com> wrote:
> If you decide to make a PEP, please list the other algorithms you found and
> their definitions.  Personally, I'm for being consistent with numpy and
> defining math.isclose similar to numpy.isclose for consistency alone.

Good point.

Also, in the PEP, cover the use cases being considered as relevant
(and just as importantly, those which aren't). As a person who doesn't
really do much numerical coding, I see the following cases where I'd
even consider using a function like this:

1. Testing when to stop with an iterative algorithm. These would
normally be "toy" examples, because if the right answer really
mattered to me, I would probably be using a specialised function (from
somewhere like numpy or mpmath).
2. Comparing with decimal literals ("is nearly 0.1"). But I hope I
would immediately rethink in that case, as I know that the issue here
is not about being "nearly equal" but about representability of
decimals as floats. If not, this use case counts more as an attractive
nuisance than as a valid use case.
3. Dealing with approximate measurements. I can sort of imagine uses
for this, but it's not something I've ever needed, so again I'd
probably be more likely to reach for a specialist module or some
literature rather than just hitting it with a stdlib function.

I guess using it (with a full understanding of how it worked) in the
internals of the sort of specialist function that I'd expect to use
(such as the statistics module that's been mentioned in this thread)
is probably the main use case I can see.

In summary, I can't really think of a case in my experience as a
non-specialist where I'd consider a stdlib function to be the right
answer for my use. So spelling out in the PEP those cases where it
would be useful is pretty important.

Paul


More information about the Python-ideas mailing list