On Wed, Jul 9, 2014 at 12:05 PM, Tim Chase
<[email protected]> wrote:
> def equalish(x, y):
> return x == y or (math.isnan(x) and math.isnan(y))
With more generality:
def nan_type(x):
if isinstance(x, numbers.Complex):
if cmath.isnan(x): return 'qnan'
elif isinstance(x, decimal.Decimal):
if x.is_qnan(): return 'qnan'
if x.is_snan(): return 'snan'
return None
def equalish(x, y):
if x is y or x == y: return True
x_nan = nan_type(x)
return x_nan is not None and x_nan == nan_type(y)
Have I missed any cases?
--
https://mail.python.org/mailman/listinfo/python-list