cpython
cpython copied to clipboard
gh-71385: add relative delta parameter for assertAlmostEqual and assertNotAlmostEqual
relative delta keyword for assertAlmostEqual and assertNotAlmostEqual #71385
gh-71385: a keyword "rel_delta" is introduced to the functions assertAlmostEqual and assertNotAlmostEqual to allow comparisons based on the relative difference of two values
more detailed history in the corresponding issue #71385
Most changes to Python require a NEWS entry.
Please add it using the blurb_it web app or the blurb command-line tool.
@wehlgrundspitze your PR title should be: gh-71385: add relative delta parameter for assertAlmostEqual and assertNotAlmostEqual
Thanks for your comments and feedback. I implemented them all and hope for acceptance.
It seems to me that both existing and modified code don't have defined behavior when one (or both) input are either float('nan') or float('inf'). Especially assertNotAlmostEqual will fail when both of it's arguments are NaNs. This is different than math.isclose() and potentially confusing. https://docs.python.org/3/library/math.html#math.isclose Either we fix it or at least add a note in docstring.
That was a great remark. I fixed the algorithm to handle +-inf and NaN according to IEEE 754 (and therefore consistent with math.isclose) and wrote an additional test about it.