gcd implementation for smallint.