py2/h2o_util.py
def approxEqual(x, y, *args, **kwargs):
    """approxEqual(float1, float2[, tol=1e-18, rel=1e-7]) -> True|False
    approxEqual(obj1, obj2[, *args, **kwargs]) -> True|False

    Return True if x and y are approximately equal, otherwise False.

    If x and y are floats, return True if y is within either absolute error
    tol or relative error rel of x. You can disable either the absolute or
    relative check by passing None as tol or rel (but not both).

    For any other objects, x and y are checked in that order for a method
    __approxEqual__, and the result of that is returned as a bool. Any
    optional arguments are passed to the __approxEqual__ method.

    __approxEqual__ can return NotImplemented to signal that it doesn't know
    how to perform that specific comparison, in which case the other object is
    checked instead. If neither object have the method, or both defer by
    returning NotImplemented, approxEqual falls back on the same numeric
    comparison used for floats.

    >>> almost_equal(1.2345678, 1.2345677)
    True
    >>> almost_equal(1.234, 1.235)
    False

    """
    if not (type(x) is type(y) is float):
        # Skip checking for __approxEqual__ in the common case of two floats.
        methodname = '__approxEqual__'
        # Allow the objects to specify what they consider "approximately equal",
        # giving precedence to x. If either object has the appropriate method, we
        # pass on any optional arguments untouched.
        for a,b in ((x, y), (y, x)):
            try:
                method = getattr(a, methodname)
            except AttributeError:
                continue
            else:
                result = method(b, *args, **kwargs)
                if result is NotImplemented:
                    print "WARNING: NotImplemented approxEqual for types"
                    continue
                return bool(result)

    # If we get here without returning, then neither x nor y knows how to do an
    # approximate equal comparison (or are both floats). Fall back to a numeric
    # comparison.
    return _float_approxEqual(x, y, *args, **kwargs)
def approxEqual(x, y, *args, **kwargs):
    """approxEqual(float1, float2[, tol=1e-18, rel=1e-7]) -> True|False
    approxEqual(obj1, obj2[, *args, **kwargs]) -> True|False

    Return True if x and y are approximately equal, otherwise False.

    If x and y are floats, return True if y is within either absolute error
    tol or relative error rel of x. You can disable either the absolute or
    relative check by passing None as tol or rel (but not both).

    For any other objects, x and y are checked in that order for a method
    __approxEqual__, and the result of that is returned as a bool. Any
    optional arguments are passed to the __approxEqual__ method.

    __approxEqual__ can return NotImplemented to signal that it doesn't know
    how to perform that specific comparison, in which case the other object is
    checked instead. If neither object have the method, or both defer by
    returning NotImplemented, approxEqual falls back on the same numeric
    comparison used for floats.

    >>> almost_equal(1.2345678, 1.2345677)
    True
    >>> almost_equal(1.234, 1.235)
    False

    """
    if not (type(x) is type(y) is float):
        # Skip checking for __approxEqual__ in the common case of two floats.
        methodname = '__approxEqual__'
        # Allow the objects to specify what they consider "approximately equal",
        # giving precedence to x. If either object has the appropriate method, we
        # pass on any optional arguments untouched.
        for a,b in ((x, y), (y, x)):
            try:
                method = getattr(a, methodname)
            except AttributeError:
                continue
            else:
                result = method(b, *args, **kwargs)
                if result is NotImplemented:
                    print "WARNING: NotImplemented approxEqual for types"
                    continue
                return bool(result)

    # If we get here without returning, then neither x nor y knows how to do an
    # approximate equal comparison (or are both floats). Fall back to a numeric
    # comparison.
    return _float_approxEqual(x, y, *args, **kwargs)
def approxEqual ( x , y , * args , * * kwargs ) : if not ( type ( x ) is type ( y ) is float ) : # Skip checking for __approxEqual__ in the common case of two floats. methodname = '__approxEqual__' # Allow the objects to specify what they consider "approximately equal", # giving precedence to x. If either object has the appropriate method, we # pass on any optional arguments untouched. for a , b in ( ( x , y ) , ( y , x ) ) : try : method = getattr ( a , methodname ) except AttributeError : continue else : result = method ( b , * args , * * kwargs ) if result is NotImplemented : print "WARNING: NotImplemented approxEqual for types" continue return bool ( result ) # If we get here without returning, then neither x nor y knows how to do an # approximate equal comparison (or are both floats). Fall back to a numeric # comparison. return _float_approxEqual ( x , y , * args , * * kwargs )
approxEqual(float1, float2[, tol=1e-18, rel=1e-7]) -> True|False
    approxEqual(obj1, obj2[, *args, **kwargs]) -> True|False

    Return True if x and y are approximately equal, otherwise False.

    If x and y are floats, return True if y is within either absolute error
    tol or relative error rel of x. You can disable either the absolute or
    relative check by passing None as tol or rel (but not both).

    For any other objects, x and y are checked in that order for a method
    __approxEqual__, and the result of that is returned as a bool. Any
    optional arguments are passed to the __approxEqual__ method.

    __approxEqual__ can return NotImplemented to signal that it doesn't know
    how to perform that specific comparison, in which case the other object is
    checked instead. If neither object have the method, or both defer by
    returning NotImplemented, approxEqual falls back on the same numeric
    comparison used for floats.

    >>> almost_equal(1.2345678, 1.2345677)
    True
    >>> almost_equal(1.234, 1.235)
    False
approxEqual ( float1 float2 [ tol = 1e - 18 rel = 1e - 7 ] ) - > True|False approxEqual ( obj1 obj2 [ * args ** kwargs ] ) - > True|False