summaryrefslogtreecommitdiff
path: root/lib/complex.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-01-17 08:37:53 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-01-17 08:37:53 +0000
commitdde62bcd2efbb3825d982326896ab774e73e4218 (patch)
tree6a421d3818dd390cf8f6b2c5544726a8950e1401 /lib/complex.rb
parente43877719bd4bbd12e493e896a0f98c5b349937b (diff)
2000-01-17
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/complex.rb')
-rw-r--r--lib/complex.rb32
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/complex.rb b/lib/complex.rb
index 0af8c20b89..56dd040ac1 100644
--- a/lib/complex.rb
+++ b/lib/complex.rb
@@ -20,7 +20,7 @@
# Complex::/
# Complex::**
# Complex::%
-# Complex::divmod
+# Complex::divmod -- obsolete
# Complex::abs
# Complex::abs2
# Complex::arg
@@ -51,6 +51,12 @@
def Complex(a, b = 0)
if a.kind_of?(Complex) and b == 0
a
+ elsif b.kind_of?(Complex)
+ if a.kind_of?(Complex)
+ Complex(a.real-b.image, a.image + b.real)
+ else
+ Complex(a-b.image, b.real)
+ end
elsif b == 0 and defined? Complex::Unify
a
else
@@ -181,18 +187,18 @@ class Complex < Numeric
end
end
- def divmod(other)
- if other.kind_of?(Complex)
- rdiv, rmod = @real.divmod(other.real)
- idiv, imod = @image.divmod(other.image)
- return Complex(rdiv, idiv), Complex(rmod, rdiv)
- elsif Complex.generic?(other)
- Complex(@real.divmod(other), @image.divmod(other))
- else
- x , y = other.coerce(self)
- x.divmod(y)
- end
- end
+# def divmod(other)
+# if other.kind_of?(Complex)
+# rdiv, rmod = @real.divmod(other.real)
+# idiv, imod = @image.divmod(other.image)
+# return Complex(rdiv, idiv), Complex(rmod, rmod)
+# elsif Complex.generic?(other)
+# Complex(@real.divmod(other), @image.divmod(other))
+# else
+# x , y = other.coerce(self)
+# x.divmod(y)
+# end
+# end
def abs
Math.sqrt!((@real*@real + @image*@image).to_f)