summaryrefslogtreecommitdiff
path: root/lib/complex.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-08-13 05:45:20 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-08-13 05:45:20 +0000
commit65a5162550f58047974793cdc8067a970b2435c0 (patch)
tree082bb7d5568f3b2e36e3fe166e9f3039394fcf44 /lib/complex.rb
parentfcd020c83028f5610d382e85a2df00223e12bd7e (diff)
1.4.0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/complex.rb')
-rw-r--r--lib/complex.rb18
1 files changed, 10 insertions, 8 deletions
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