def is_nan(x): return type(x) is float and x != x
def is_finite(x): return x not in (Infinity, -Infinity)