On this page
math.isclose
Prev: math.hypot | Up: math | Next: math.isfinite
Rel: math.acos, math.acosh, math.asin, math.asinh
Ref: docs.python.org — math.isclose
Tags: #public #python3 #stdlib #math
Import
import math
from math import isclose
Signature & Overview
math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)
Determine whether two floating-point numbers are close in value.
Usage
import math
assert math.isclose(0.1 + 0.2, 0.3)
assert math.isclose(1e-10, 0.0, abs_tol=1e-9)
Gotchas
- Always pass
abs_tol=when comparing against0.0: Defaultabs_tol=0.0meansmath.isclose(1e-12, 0.0)isFalsebecause relative tolerance against zero is zero.
REPL Inspect
from math import isclose
help(isclose)
Linked from
Related notes
- tuts/python3/stdlib_module/math/hypot Linked here; links to this page; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/isfinite Linked here; links to this page; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/math/acos Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/acosh Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/asin Linked here; shared tags: #math, #stdlib
- tuts/python3/stdlib_module/math/asinh Linked here; shared tags: #math, #stdlib
- tuts/c/stdlib/math shared tags: #math, #stdlib
- tuts/c/stdlib/math/fabs shared tags: #math, #stdlib
- tuts/c/stdlib/math/floor shared tags: #math, #stdlib