def approx_equal(x, y, tol=1e-12, rel=1e-07):
 if ((tol < 0) or (rel < 0)):
  raise ValueError('error tolerances must be non-negative')
 if (math.isnan(x) or math.isnan(y)):
  return False
 if (x == y):
  return True
 if (math.isinf(x) or math.isinf(y)):
  return False
 actual_error = abs((x - y))
 allowed_error = max(tol, (rel * max(abs(x), abs(y))))
 return (actual_error <= allowed_error)

def approx_equal ( x , y , tol = 1e-12 , rel = 1e-07 ) : if ( ( tol < 0 ) or ( rel < 0 ) ) : raise ValueError ( 'error tolerances must be non-negative' ) if ( math . isnan ( x ) or math . isnan ( y ) ) : return False if ( x == y ) : return True if ( math . isinf ( x ) or math . isinf ( y ) ) : return False actual_error = abs ( ( x - y ) ) allowed_error = max ( tol , ( rel * max ( abs ( x ) , abs ( y ) ) ) ) return ( actual_error <= allowed_error )
approx_equal => true|false return true if numbers x and y are approximately equal .