summaryrefslogtreecommitdiff
path: root/lib/complex.rb
diff options
context:
space:
mode:
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 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