Home

Isclose

Isclose refers to the concept of determining whether two numerical values are approximately equal within a defined tolerance rather than exactly equal. In numerical computing, exact equality can be unreliable due to floating point representation, rounding errors, and measurement noise. An isclose test provides a robust way to compare values in algorithms, tests, and simulations.

In programming, isclose is implemented in several libraries with similar semantics. For example, Python’s math.isclose(a, b,

NumPy also provides isclose for array-like inputs: numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False). It broadcasts over arrays

Practical guidance on tolerances varies by context. Relative tolerance (rtol) is suitable for large numbers, while

See also: relative error, machine epsilon, floating point arithmetic, numerical stability.

rel_tol=1e-09,
abs_tol=0.0)
returns
True
if
the
absolute
difference
between
a
and
b
is
at
most
the
larger
of
rel_tol
times
the
larger
absolute
value
of
a
or
b,
and
abs_tol.
Formally,
it
checks
whether
abs(a
-
b)
<=
max(rel_tol
*
max(abs(a),
abs(b)),
abs_tol).
By
default,
NaN
comparisons
are
False.
and
returns
a
boolean
array
indicating
where
elements
are
close.
The
same
general
idea
applies,
with
rtol
and
atol
controlling
relative
and
absolute
tolerance,
and
equal_nan
allowing
NaNs
to
be
treated
as
equal
when
desired.
absolute
tolerance
(atol)
helps
near
zero.
In
high-stakes
calculations,
calibrate
tolerances
to
the
expected
error
bounds
of
the
numerical
method.
Isclose
is
not
a
universal
substitute
for
equality
and
should
be
used
with
awareness
of
its
limitations
and
the
non-transitive
nature
of
approximate
comparisons.