Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Floating point math fun! Since equality tests on floats are a crap shoot,
- # instead check if floats are almost equal (is the first float within a
- # certain tolerance amount of the second).
- # Note, this function may fail in certain circumstances depending on the
- # number of significant figures. If comparisons become problematic, you can
- # try a different power of ten for the "tol" value (eg 0.01 or 0.00001)
- def floatsAlmEq(f1,f2):
- tol = 0.0001
- return f1 > (f2 - tol) and f1 < (f2 + tol)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement