diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-03-30 14:50:55 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-03-30 14:50:55 +0000 |
commit | 3730710d79aa0bde6ab5b36e18c734dd9718aac0 (patch) | |
tree | c2da11a0d90c4625c04880075baa333a44835aae /lib/rational.rb | |
parent | c8ac4a209bcccfe38239ff3e6e853cf01e424537 (diff) | |
download | ruby-3730710d79aa0bde6ab5b36e18c734dd9718aac0.tar.gz |
* 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/rational.rb')
-rw-r--r-- | lib/rational.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/rational.rb b/lib/rational.rb index 87c5d3f111..b12bf7ef38 100644 --- a/lib/rational.rb +++ b/lib/rational.rb @@ -15,3 +15,35 @@ class Bignum alias rpower ** end + +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 |