[Python-ideas] Way to check for floating point "closeness"?
Chris Barker
chris.barker at noaa.gov
Mon Jan 12 18:02:17 CET 2015
Now that we're talking about floating point conveniences (math.nan,
linspace):
What about putting an
almost_equal(x,y,tol=1e14)
(or close(), or...) in the math module.
AFAICT, in the standard library, there is only:
unittest.TestCase.assertAlmostEqual
but it:
A) is buried in the unittest.TestCase class
B) is an assertion, so you can't use it as a general test (easily)
C) uses number of decimal digits or an absolute delta, but does not provide
a significant figures comparison, which is most likely what's wanted (and a
bit harder to write yourself)
numpy provides allclose() (and isclose() ), which is pretty much what I'm
suggesting.
Anyone else think this would be a good idea to add to the stdlib?
-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/20150112/790b8a28/attachment.html>
More information about the Python-ideas
mailing list