From dde62bcd2efbb3825d982326896ab774e73e4218 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 17 Jan 2000 08:37:53 +0000 Subject: 2000-01-17 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/complex.rb | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'lib/complex.rb') 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) -- cgit v1.2.3