[Python-ideas] Way to check for floating point "closeness"?
Neil Girdhar
mistersheik at gmail.com
Thu Jan 15 22:53:08 CET 2015
Note also that it does something reasonable with zero, which most of the
proposals here do not do.
On Thu, Jan 15, 2015 at 4:52 PM, Neil Girdhar <mistersheik at gmail.com> wrote:
> The point is that this function is already in Python and if you want to do
> something different, you should have a really good reason to do it
> differently. If you were to add a function to math, say math.close, it
> should work like numpy.allclose in my opinion.
>
> For reference, numpy does this:
>
> absolute(*a* - *b*) <= (*atol* + *rtol* * absolute(*b*))
>
> where atol is an absolute tolerance and rtol is a relative tolerance
> (relative to the actual value b). This subsumes most of the proposals here.
>
> Best,
>
> Neil
>
> On Wed, Jan 14, 2015 at 7:48 PM, Chris Barker <chris.barker at noaa.gov>
> wrote:
>
>> On Wed, Jan 14, 2015 at 4:23 PM, Neil Girdhar <mistersheik at gmail.com>
>> wrote:
>>
>>> You might be interested in my question:
>>>
>>>
>>> http://stackoverflow.com/questions/4028889/floating-point-equality-in-python
>>>
>>
>> nothing new there, I'm afaid -- and no one seemed to have brought up the
>> issue with zero.
>>
>> -Chris
>>
>>
>> --
>>
>> 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/python-ideas/attachments/20150115/c3520bd3/attachment.html>
More information about the Python-ideas
mailing list