Method: Integer#gcdlcm

Defined in:
lib/framework/rational18.rb,
lib/framework/rationalME.rb

#gcdlcm(other) ⇒ Object

Returns the GCD and the LCM (see #gcd and #lcm) of the two arguments (self and other). This is more efficient than calculating them separately.

Example:

6.gcdlcm 9     # -> [3, 18]


475
476
477
478
479
480
481
482
# File 'lib/framework/rational18.rb', line 475

def gcdlcm(other)
  gcd = self.gcd(other)
  if self.zero? or other.zero?
    [gcd, 0]
  else
    [gcd, (self.div(gcd) * other).abs]
  end
end