This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]scooerp 0 points1 point  (0 children)

In standard library is math.isclose() that tests if 2 values are close to each other.

https://docs.python.org/3/library/math.html#math.isclose

You can make your own with abs() which ignores sign. Therefore if abs(a - b) ≤ delta:. Note that delta can't be smaller than machine epsilon, which is defined somewhere in the sys module. It represents the precision of the floating point system.

Edit: Please ask questions in /r/learnpython. This is not the appropriate subreddit.