function g = gcd1 ( a, b )

%
%  Check input.
%  Lunatic MATLAB function isinteger() doesn't do what you think!
%  Lunatic MATLAB function int() doesn't do what you think!
%
  if ( a ~= round ( a ) )
    error ( 'gcd1(): input a is not an integer!' )
  end

  if ( a == 0 )
    error ( 'gcd1(): input a is zero!' )
  end

  if ( b ~= round ( b ) )
    error ( 'gcd1(): input b is not an integer!' )
  end

  if ( b == 0 )
    error ( 'gcd1(): input b is zero!' )
  end
%
%  Clean up input.
%
  a = abs ( a );
  b = abs ( b );

  c = max ( a, b );
  d = min ( a, b );
%
%  Until equal, subtract smaller from larger.
%
  while ( c ~= d )

    if ( c < d )
      d = d - c;
    else
      c = c - d;
    end

  end

  g = c;

  return
end

