summaryrefslogtreecommitdiff
path: root/lib/complex.rb
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-15 11:39:50 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-15 11:39:50 +0000
commitc786b2e6ae95b644270bd7755b3caeb6a25491a4 (patch)
tree825387a701f62c19c0f3960e8073c539ce0f2a2f /lib/complex.rb
parentca99b96bc9d2a0c8dc2c9cf8c8b56d58b606e723 (diff)
* lib/rational.rb (floor, ceil, truncate, round): do not use
definitions of Numeric. * lib/rational.rb (to_i): should returns truncated self. * lib/complex.rb (numerator): requires Integer#{numerator,denominator}. * lib/complex.rb (quo): do not use definition of Numeric. * lib/complex.rb (div, divmod, floor, ceil, truncate, round): undef'ed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@15489 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 9300f391e8..fbf50ffece 100644
--- a/lib/complex.rb
+++ b/lib/complex.rb
@@ -102,6 +102,8 @@ class Complex < Numeric
@RCS_ID='-$Id: complex.rb,v 1.3 1998/07/08 10:05:28 keiju Exp keiju $-'
undef step
+ undef div, divmod
+ undef floor, truncate, ceil, round
def Complex.generic?(other) # :nodoc:
other.kind_of?(Integer) or
@@ -194,6 +196,10 @@ class Complex < Numeric
end
end
+ def quo(other)
+ Complex(@real.quo(1), @image.quo(1)) / other
+ end
+
#
# Raise this complex number to the given (real or complex) power.
#
@@ -409,8 +415,34 @@ class Complex < Numeric
end
+class Integer
+
+ unless defined?(1.numerator)
+ def numerator() self end
+ def denominator() 1 end
+
+ 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
+ end
+end
module Math
alias sqrt! sqrt