[Python-ideas] Way to check for floating point "closeness"?

Chris Barker - NOAA Federal chris.barker at noaa.gov
Fri Jan 16 00:47:25 CET 2015


On Jan 15, 2015, at 3:31 PM, Neil Girdhar <mistersheik at gmail.com> wrote:
absolute(*a* - *b*) <= (*atol* + *rtol* * absolute(*b*))
Oh, and if the numbers are small, then adding the absolute tolerance
changes the tolerance significantly -- so you don't get what you expect
there, either.

Chris




>> 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.
>>
>
> adding atol  in there "takes care of" the near zero and straddleing zero
> issue ( I suspect that's why it's done that way), but it is fatally wrong
> for values much less than 1.0 --  the atol totally overwhelms the rtol.
>
> See my post earlier today.
>
> -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/916727fd/attachment.html>


More information about the Python-ideas mailing list