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
[EMAIL PROTECTED]

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to