summaryrefslogtreecommitdiff
path: root/lib/complex.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-30 14:50:55 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-03-30 14:50:55 +0000
commit3730710d79aa0bde6ab5b36e18c734dd9718aac0 (patch)
treec2da11a0d90c4625c04880075baa333a44835aae /lib/complex.rb
parentc8ac4a209bcccfe38239ff3e6e853cf01e424537 (diff)
* 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
Diffstat (limited to 'lib/complex.rb')
-rw-r--r--lib/complex.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/complex.rb b/lib/complex.rb
index 9d92602..505b012 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