[Python-Dev] math.areclose ...? (original) (raw)
Scott David Daniels Scott.Daniels at Acm.Org
Wed Feb 8 17:11:55 CET 2006
- Previous message: [Python-Dev] math.areclose ...?
- Next message: [Python-Dev] Weekly Python Patch/Bug Summary
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Smith wrote:
... There is a problem with dividing by 'ave' if the x and y are at the floating point limits, but the symmetric behaving form (presented by Scott Daniels) will have the same problem. Upon reflection, 'max' is probably better than averaging, and avoiding divide is also a reasonably good idea. Note that relative_tol < 1.0 (typically) so underflow, rather than overflow, is the issue:
def nearby(x, y, relative_tol=1.e-5, absolute_tol=1.e-8):
difference = abs(x - y)
return (difference <= absolute_tol or
difference <= max(abs(x), abs(y)) * relative_tol)
I use <=, since "zero-tolerance" should pass equal values.
--Scott David Daniels scott.Daniels at Acm.Org
- Previous message: [Python-Dev] math.areclose ...?
- Next message: [Python-Dev] Weekly Python Patch/Bug Summary
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]