Skip to content

Commit 96d451a

Browse files
Xiaokang2022skirpichevwillingcterryjreedy
authored andcommitted
pythongh-126165: Improve docs of function math.isclose (python#126215)
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 342bb2e commit 96d451a

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
@@ -244,19 +244,21 @@ Number-theoretic and representation functions
244244
``False`` otherwise.
245245

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

249250
*rel_tol* is the relative tolerance -- it is the maximum allowed difference
250251
between *a* and *b*, relative to the larger absolute value of *a* or *b*.
251252
For example, to set a tolerance of 5%, pass ``rel_tol=0.05``. The default
252253
tolerance is ``1e-09``, which assures that the two values are the same
253-
within about 9 decimal digits. *rel_tol* must be greater than zero.
254-
255-
*abs_tol* is the minimum absolute tolerance -- useful for comparisons near
256-
zero. *abs_tol* must be at least zero.
257-
258-
If no errors occur, the result will be:
259-
``abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)``.
254+
within about 9 decimal digits. *rel_tol* must be nonnegative and less
255+
than ``1.0``.
256+
257+
*abs_tol* is the absolute tolerance; it defaults to ``0.0`` and it must be
258+
nonnegative. When comparing ``x`` to ``0.0``, ``isclose(x, 0)`` is computed
259+
as ``abs(x) <= rel_tol * abs(x)``, which is ``False`` for any ``x`` and
260+
rel_tol less than ``1.0``. So add an appropriate positive abs_tol argument
261+
to the call.
260262

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

0 commit comments

Comments
 (0)