Returns the greatest common divisor of self and o

assert 54.gcd(24)   == 6
assert -54.gcd(-24) == 6
assert 54.gcd(-24)  == -6
assert -54.gcd(24)  == -6
assert 12.gcd(6)    == 6

Property definitions

core :: math $ Int :: gcd
	# Returns the greatest common divisor of `self` and `o`
	#
	#     assert 54.gcd(24)   == 6
	#     assert -54.gcd(-24) == 6
	#     assert 54.gcd(-24)  == -6
	#     assert -54.gcd(24)  == -6
	#     assert 12.gcd(6)    == 6
	fun gcd(o: Int): Int
	do
		if self < 0 then return -(-self).gcd(o)
		if o < 0 then return -(self.gcd(-o))
		if self == 0 or o == self then return o
		if o == 0 then return self
		if self & 1 == 0 then
			if o & 1 == 1 then
				return (self >> 1).gcd(o)
			else
				return (self >> 1).gcd(o >> 1) << 1
			end
		end
		if o & 1 == 0 then return self.gcd(o >> 1)
		if self > o then return ((self - o) >> 1).gcd(o)
		return ((o - self) >> 1).gcd(self)
	end
lib/core/math.nit:92,2--115,4