summaryrefslogtreecommitdiff
path: root/lib/complex.rb
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-12 11:47:12 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-02-12 11:47:12 +0000
commit2b72892ac0de9ff1d05f2b21ed85ef09aa41c57e (patch)
tree8e3605387126d68c7340fc53dda5de1455a6e090 /lib/complex.rb
parent7d4defbe1b3b267695446adac950d726538ea621 (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 (>, >=, <, <=, between?, div, divmod, modulo, floor, ceil, truncate, round): undef'ed. * lib/mathn.rb (Rational#inspect): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/complex.rb')
-rw-r--r--lib/complex.rb41
1 files changed, 38 insertions, 3 deletions
diff --git a/lib/complex.rb b/lib/complex.rb
index eb2d5d6..9a621c0 100644
--- a/lib/complex.rb
+++ b/lib/complex.rb
@@ -104,6 +104,10 @@ class Complex < Numeric
@RCS_ID='-$Id: complex.rb,v 1.3 1998/07/08 10:05:28 keiju Exp keiju $-'
undef step
+ undef <, <=, <=>, >, >=
+ undef between?
+ undef div, divmod, modulo
+ undef floor, truncate, ceil, round
def scalar?
false
@@ -199,6 +203,10 @@ class Complex < Numeric
x/y
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.
@@ -248,6 +256,8 @@ class Complex < Numeric
#
# Remainder after division by a real or complex number.
#
+
+=begin
def % (other)
if other.kind_of?(Complex)
Complex(@real % other.real, @image % other.image)
@@ -258,7 +268,8 @@ class Complex < Numeric
x % y
end
end
-
+=end
+
#--
# def divmod(other)
# if other.kind_of?(Complex)
@@ -312,8 +323,6 @@ class Complex < Numeric
end
alias conj conjugate
- undef <=>
-
#
# Test for numerical equality (<tt>a == a + 0<i>i</i></tt>).
#
@@ -410,8 +419,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