This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ChrisBarker
Recipients ChrisBarker, ezio.melotti, michael.foord, rbcollins
Date 2016-06-03.18:48:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1464979712.74.0.398203716413.issue27198@psf.upfronthosting.co.za>
In-reply-to
Content
In py3.5, the math.isclose() function was added to the standard library. It can be used to compare floating point numbers to see if they are close to each other, rather than exactly equal. It's not a lot of code, but there are nuances that not every python user should need to understand.

One of the major use cases for isclose() is test code, so it would be good to make it easily available in unitest.TestCase.

TestCase.assertAlmostEqual is NOT the same thing, and can only be used properly for values near 1.

Enclosed is a patch that adds  assertClose and assertNotClose to unittest, as well as tests and additions to the docs.

Still pending: should this support complex numbers, there is a cmath.isclose(). If so, but switching on type?

Also -- should this be back-ported to 3.5 as well -- math.isclose() was introduced there.

Done in the pyCon sprints.
History
Date User Action Args
2016-06-03 18:48:32ChrisBarkersetrecipients: + ChrisBarker, rbcollins, ezio.melotti, michael.foord
2016-06-03 18:48:32ChrisBarkersetmessageid: <1464979712.74.0.398203716413.issue27198@psf.upfronthosting.co.za>
2016-06-03 18:48:32ChrisBarkerlinkissue27198 messages
2016-06-03 18:48:32ChrisBarkercreate