Math Functions

math.isclose()

Compare real values using relative and absolute tolerances. NaN is never close; infinities only match themselves. Use absolute tolerance near zero.

Formal Syntax & Structure

python syntaxpython
math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)

Parameters & Attributes

NameTypeDescription
areal numberFirst value to compare.
breal numberSecond value to compare.
rel_tolfloatNonnegative relative comparison tolerance.
abs_tolfloatNonnegative absolute comparison tolerance.

Return Value

bool

True when the described condition holds, otherwise False.

Working Example

Example Snippetpython
import mathprint(math.isclose(0.1 + 0.2, 0.3))
Python Reference