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

cy18 thecy18 at gmail.com
Mon Oct 19 16:51:28 EDT 2015


It would be useful when we need to subtracting a bit before comparing by
greater or less. By subtracting a bit, we only have an absolute error
tolerance and with the new functions, we can have both absolute and
relative error tolerance. This is how isclose(a, b) better than
abs(a-b)<=atol.


2015-10-19 15:46 GMT-04:00 Chris Barker <chris.barker at noaa.gov>:

>
>
> 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
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20151019/e0ec7260/attachment.html>


More information about the NumPy-Discussion mailing list