Georg Brandl wrote:
> Alex Martelli wrote:
>>So I was wondering if module math (and perhaps by symmetry module cmath, 
>> too) shouldn't grow a function 'areclose' ...maybe ... 'almost_equal')
>> def areclose(x, y, rtol=1.e-5, atol=1.e-8):
>>      return abs(x-y)<atol+rtol*abs(y)
> 
> atol sounds suspicious to me, but otherwise fine.

"almost_equal", "closeto", or some variant of "near" (no nasty verb to
worry about) would do for me.  atol / rtol would be better as either
abs_tol / rel_tol or even absolute_tolerance / relative_tolerance.

As to the equation itself, wouldn't a symmetric version be somewhat
better?

     def nearby(x, y, rel_tol=1.e-5, abs_tol=1.e-8):
         return abs(x - y) < abs_tol + rel_tol * (abs(x) + abs(y))

This avoids areclose(0, 1e-8) != areclose(1e-8, 0), for example.

--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