[Numpy-discussion] [Feature Suggestion]More comparison functions for floating point numbers

Chris Barker chris.barker at noaa.gov
Mon Oct 19 15:46:27 EDT 2015


On Mon, Oct 19, 2015 at 3:06 AM, cy18 <thecy18 at gmail.com> wrote:

> I think these would be useful and easy to implement.
>
>     greater_close(a, b) = greater_equal(a, b) | isclose(a, b)
>     less_close(a, b) = less_equal(a, b) | isclose(a, b)
>     greater_no_close = greater(a, b) & ~isclose(a, b)
>     less_no_close = less(a, b) & ~isclose(a, b)
>

What's the use-case here? we need is_close because we want to test
equality, but precision errors are such that two floats may be as close to
equal as they can be given the computations done. And the assumption is
that you don't care about the precision to the point you specify.

But for a greater_than (or equiv) comparison, if you the precision is not
important beyond a certain level, then it's generally not important whether
you get greater than or less than when it's that close....

And this would great a wierd property that some values would be greater
than, less than, and equal to a target value -- pretty weird!

note that you can get the same effect by subtracting a bit from your
comparison value for a greater than check...

But maybe there is a common use-case that I'm not thinking of..

-CHB

-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20151019/0a678e1f/attachment.html>


More information about the NumPy-Discussion mailing list