python compare floats

Solutions on MaxInterview for python compare floats by the best coders in the world

showing results for - "python compare floats"
Lara
26 Jan 2020
1import numpy as np
2np.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)
3
Eric
03 Apr 2019
1# credit to the Stack Overflow user in the source link
2# method of the 'math' module
3
4def isclose(a, b, rel_tol=1e-09, abs_tol=0.0):
5    return abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)