Greatest common divisor

You are encouraged to solve this task according to the task description, using any language you may know.
Task

Find the greatest common divisor   (GCD)   of two integers.


Greatest common divisor   is also known as   greatest common factor (gcf)   and   greatest common measure.



Related task

   least common multiple.


See also

   MathWorld entry:   greatest common divisor.
   Wikipedia entry:     greatest common divisor.


class MATH is
 
  gcd_iter(u, v:INT):INT is
    loop while!( v.bool );
      t ::= u; u := v; v := t % v;
    end;
    return u.abs;
  end;
 
  gcd(u, v:INT):INT is
    if v.bool then return gcd(v, u%v); end;
    return u.abs;
  end;
 
 
  private swap(inout a, inout b:INT) is
    t ::= a;
    a := b;
    b := t;
  end;
 
  gcd_bin(u, v:INT):INT is
    t:INT;
 
    u := u.abs; v := v.abs;
    if u < v then swap(inout u, inout v); end;
    if v = 0 then return u; end;
    k ::= 1;
    loop while!( u.is_even and v.is_even );
      u := u / 2; v := v / 2;
      k := k * 2;
    end;
    if u.is_even then
      t := -v;
    else
      t := u;
    end;
    loop while!( t.bool );
      loop while!( t.is_even );
        t := t / 2;
      end;
      if t > 0 then 
        u := t;
      else
        v := -t;
      end;
      t := u - v;
    end;
    return u * k;
  end;
 
end;