From 3730710d79aa0bde6ab5b36e18c734dd9718aac0 Mon Sep 17 00:00:00 2001 From: matz Date: Sun, 30 Mar 2008 14:50:55 +0000 Subject: * proc.c (proc_dup): should copy is_lambda attribute as well. [ruby-talk:296244] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/complex.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/complex.rb') diff --git a/lib/complex.rb b/lib/complex.rb index 9d926023a7..505b0120e3 100644 --- a/lib/complex.rb +++ b/lib/complex.rb @@ -1,3 +1,35 @@ +class Integer + + def gcd(other) + min = self.abs + max = other.abs + while min > 0 + tmp = min + min = max % min + max = tmp + end + max + end + + def lcm(other) + if self.zero? or other.zero? + 0 + else + (self.div(self.gcd(other)) * other).abs + end + end + + def gcdlcm(other) + gcd = self.gcd(other) + if self.zero? or other.zero? + [gcd, 0] + else + [gcd, (self.div(gcd) * other).abs] + end + end + +end + module Math alias exp! exp -- cgit v1.2.3