def gcd(a, b):
  """General implementation of Euclidean algorithm.
  
  A general Euclidean algorithm for any number type with a divmod and a
  valuation abs() whose minimum value is zero. Note that this implementation
  can work with objects and not just native Python bigints.
  """
  if abs(a) < abs(b):
    return gcd(b, a)

  while abs(b) > 0:
    _, r = divmod(a, b)
    a, b = b, r

  return a