
One option would be to add a zero_tol argument, which is an absolute
tolerance that is only applied if expected == 0.
OK -- now I know what the problem is here -- I thought I"d explored it already. If you have a tolerance that you use only when expected is zero (or when either is...) then you have teh odd reslut that a samll number will be "close" to zero, but NOT close to a smaller number. I implemented this on a branch in github: https://github.com/PythonCHB/close_pep/tree/zero_tol And you get the odd result: In [9]: is_close_to(1e-9, 0.0) Out[9]: True fine -- the default zero_tol is 1e-8 In [10]: is_close_to(1e-9, 1e-12) Out[10]: False but huh??? 1e-9 is close to zero, but not close to 1e-12???? This is why I dropped the idea before. I'm back to the key point -- relative error compared to zero is not defined -- you need to set an absolute tolerance if you want to test against zero -- and there is no default that makes sense for all (or even most) cases. I'd much rather require people to have to think about what makes sense for their use case than get trapped by a default that's totally inappropriate. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov