Apply Chris Barker's latest PEP 485 changes

This commit is contained in:
Chris Angelico 2015-01-23 11:50:29 +11:00
parent 79268209af
commit 9e4c0dd449
1 changed files with 8 additions and 4 deletions

View File

@ -82,7 +82,7 @@ comparisons near zero.
Modulo error checking, etc, the function will return the result of:: Modulo error checking, etc, the function will return the result of::
abs(expected-actual) <= max(tol*actual, abs_tol) abs(expected-actual) <= max(tol*expected, abs_tol)
Handling of non-finite numbers Handling of non-finite numbers
@ -103,7 +103,7 @@ theory, it should work for any type that supports ``abs()``,
comparisons, and subtraction. The code will be written and tested to comparisons, and subtraction. The code will be written and tested to
accommodate these types: accommodate these types:
* ``Decimal`` * ``Decimal``: for Decimal, the tolerance must be set to a Decimal type.
* ``int`` * ``int``
@ -123,12 +123,16 @@ optional parameter, ``abs_tol`` (default 0.0) can be used to set a
minimum tolerance to be used in the case of very small relative minimum tolerance to be used in the case of very small relative
tolerance. That is, the values will be considered close if:: tolerance. That is, the values will be considered close if::
abs(a-b) <= abs(tol*actual) or abs(a-b) <= abs_tol abs(a-b) <= abs(tol*expected) or abs(a-b) <= abs_tol
If the user sets the rel_tol parameter to 0.0, then only the absolute If the user sets the rel_tol parameter to 0.0, then only the absolute
tolerance will effect the result, so this function provides an tolerance will effect the result, so this function provides an
absolute tolerance check as well. absolute tolerance check as well.
A sample implementation is available (as of Jan 22, 2015) on gitHub:
https://github.com/PythonCHB/close_pep/blob/master/is_close_to.py
Relative Difference Relative Difference
=================== ===================