From 115eb4595cea72226ec8acd357e7c403e2c4b04a Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 9 Feb 1999 06:08:24 +0000 Subject: 990209 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/complex.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'lib/complex.rb') diff --git a/lib/complex.rb b/lib/complex.rb index 59caad6ebc..0af8c20b89 100644 --- a/lib/complex.rb +++ b/lib/complex.rb @@ -72,6 +72,8 @@ class Complex < Numeric end def initialize(a, b = 0) + raise "non numeric 1st arg `#{a.inspect}'" if !a.kind_of? Numeric + raise "non numeric 2nd arg `#{b.inspect}'" if !b.kind_of? Numeric @real = a @image = b end @@ -84,7 +86,7 @@ class Complex < Numeric elsif Complex.generic?(other) Complex(@real + other, @image) else - x , y = a.coerce(self) + x , y = other.coerce(self) x + y end end @@ -97,7 +99,7 @@ class Complex < Numeric elsif Complex.generic?(other) Complex(@real - other, @image) else - x , y = a.coerce(self) + x , y = other.coerce(self) x - y end end @@ -110,7 +112,7 @@ class Complex < Numeric elsif Complex.generic?(other) Complex(@real * other, @image * other) else - x , y = a.coerce(self) + x , y = other.coerce(self) x * y end end @@ -121,7 +123,7 @@ class Complex < Numeric elsif Complex.generic?(other) Complex(@real / other, @image / other) else - x , y = a.coerce(self) + x , y = other.coerce(self) x / y end end @@ -163,7 +165,7 @@ class Complex < Numeric r, theta = polar Complex.polar(r.power!(other), theta * other) else - x , y = a.coerce(self) + x , y = other.coerce(self) x / y end end @@ -174,7 +176,7 @@ class Complex < Numeric elsif Complex.generic?(other) Complex(@real % other, @image % other) else - x , y = a.coerce(self) + x , y = other.coerce(self) x % y end end @@ -187,7 +189,7 @@ class Complex < Numeric elsif Complex.generic?(other) Complex(@real.divmod(other), @image.divmod(other)) else - x , y = a.coerce(self) + x , y = other.coerce(self) x.divmod(y) end end @@ -222,7 +224,7 @@ class Complex < Numeric elsif Complex.generic?(other) @real == other and @image == 0 else - x , y = a.coerce(self) + x , y = other.coerce(self) x == y end end -- cgit v1.2.3