Skip to content

Commit d1b8718

Browse files
miss-islingtonXiaokang2022skirpichevwillingcterryjreedy
authored
[3.12] gh-126165: Improve docs of function math.isclose (GH-126215) (#126381)
gh-126165: Improve docs of function `math.isclose` (GH-126215) (cherry picked from commit 081706f) Co-authored-by: Zhikang Yan <[email protected]> Co-authored-by: Sergey B Kirpichev <[email protected]> Co-authored-by: Carol Willing <[email protected]> Co-authored-by: Terry Jan Reedy <[email protected]>
1 parent 37dc2b2 commit d1b8718

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

Doc/library/cmath.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,21 @@ Classification functions
221221
``False`` otherwise.
222222

223223
Whether or not two values are considered close is determined according to
224-
given absolute and relative tolerances.
224+
given absolute and relative tolerances. If no errors occur, the result will
225+
be: ``abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)``.
225226

226227
*rel_tol* is the relative tolerance -- it is the maximum allowed difference
227228
between *a* and *b*, relative to the larger absolute value of *a* or *b*.
228229
For example, to set a tolerance of 5%, pass ``rel_tol=0.05``. The default
229230
tolerance is ``1e-09``, which assures that the two values are the same
230-
within about 9 decimal digits. *rel_tol* must be greater than zero.
231-
232-
*abs_tol* is the minimum absolute tolerance -- useful for comparisons near
233-
zero. *abs_tol* must be at least zero.
234-
235-
If no errors occur, the result will be:
236-
``abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)``.
231+
within about 9 decimal digits. *rel_tol* must be nonnegative and less
232+
than ``1.0``.
233+
234+
*abs_tol* is the absolute tolerance; it defaults to ``0.0`` and it must be
235+
nonnegative. When comparing ``x`` to ``0.0``, ``isclose(x, 0)`` is computed
236+
as ``abs(x) <= rel_tol * abs(x)``, which is ``False`` for any ``x`` and
237+
rel_tol less than ``1.0``. So add an appropriate positive abs_tol argument
238+
to the call.
237239

238240
The IEEE 754 special values of ``NaN``, ``inf``, and ``-inf`` will be
239241
handled according to IEEE rules. Specifically, ``NaN`` is not considered

Doc/library/math.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,21 @@ Number-theoretic and representation functions
142142
``False`` otherwise.
143143

144144
Whether or not two values are considered close is determined according to
145-
given absolute and relative tolerances.
145+
given absolute and relative tolerances. If no errors occur, the result will
146+
be: ``abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)``.
146147

147148
*rel_tol* is the relative tolerance -- it is the maximum allowed difference
148149
between *a* and *b*, relative to the larger absolute value of *a* or *b*.
149150
For example, to set a tolerance of 5%, pass ``rel_tol=0.05``. The default
150151
tolerance is ``1e-09``, which assures that the two values are the same
151-
within about 9 decimal digits. *rel_tol* must be greater than zero.
152-
153-
*abs_tol* is the minimum absolute tolerance -- useful for comparisons near
154-
zero. *abs_tol* must be at least zero.
155-
156-
If no errors occur, the result will be:
157-
``abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)``.
152+
within about 9 decimal digits. *rel_tol* must be nonnegative and less
153+
than ``1.0``.
154+
155+
*abs_tol* is the absolute tolerance; it defaults to ``0.0`` and it must be
156+
nonnegative. When comparing ``x`` to ``0.0``, ``isclose(x, 0)`` is computed
157+
as ``abs(x) <= rel_tol * abs(x)``, which is ``False`` for any ``x`` and
158+
rel_tol less than ``1.0``. So add an appropriate positive abs_tol argument
159+
to the call.
158160

159161
The IEEE 754 special values of ``NaN``, ``inf``, and ``-inf`` will be
160162
handled according to IEEE rules. Specifically, ``NaN`` is not considered

0 commit comments

Comments
 (0)