summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-20 22:49:56 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-20 22:49:56 +0000
commit9467d7a02430cbe76368148fe8097d7d029e6def (patch)
tree809bc0df44376cf7d9143b6ad480f45ec5b2f250 /lib
parent67526f30909c255d164d5c14d944eeda77d8d92a (diff)
* complex.c: an instance method image has been removed and
uses "imag" instead of "image". * complex.c: two instance method re and im are removed. * rational.c: follows the above changes. * include/ruby/ruby.h: ditto. * gc.c: ditto. * lib/cmath.rb: ditto. * lib/mathn.rb: ditto. * lib/complex.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/cmath.rb32
-rw-r--r--lib/complex.rb6
-rw-r--r--lib/mathn.rb6
3 files changed, 25 insertions, 19 deletions
diff --git a/lib/cmath.rb b/lib/cmath.rb
index 795558c59b..d293401804 100644
--- a/lib/cmath.rb
+++ b/lib/cmath.rb
@@ -28,8 +28,8 @@ module CMath
if z.real?
exp!(z)
else
- Complex(exp!(z.real) * cos!(z.image),
- exp!(z.real) * sin!(z.image))
+ Complex(exp!(z.real) * cos!(z.imag),
+ exp!(z.real) * sin!(z.imag))
end
end
@@ -60,10 +60,10 @@ module CMath
if z >= 0
sqrt!(z)
else
- Complex(0,sqrt!(-z))
+ Complex(0, sqrt!(-z))
end
else
- if z.image < 0
+ if z.imag < 0
sqrt(z.conjugate).conjugate
else
r = z.abs
@@ -77,8 +77,8 @@ module CMath
if z.real?
sin!(z)
else
- Complex(sin!(z.real) * cosh!(z.image),
- cos!(z.real) * sinh!(z.image))
+ Complex(sin!(z.real) * cosh!(z.imag),
+ cos!(z.real) * sinh!(z.imag))
end
end
@@ -86,8 +86,8 @@ module CMath
if z.real?
cos!(z)
else
- Complex(cos!(z.real) * cosh!(z.image),
- -sin!(z.real) * sinh!(z.image))
+ Complex(cos!(z.real) * cosh!(z.imag),
+ -sin!(z.real) * sinh!(z.imag))
end
end
@@ -103,8 +103,8 @@ module CMath
if z.real?
sinh!(z)
else
- Complex(sinh!(z.real) * cos!(z.image),
- cosh!(z.real) * sin!(z.image))
+ Complex(sinh!(z.real) * cos!(z.imag),
+ cosh!(z.real) * sin!(z.imag))
end
end
@@ -112,8 +112,8 @@ module CMath
if z.real?
cosh!(z)
else
- Complex(cosh!(z.real) * cos!(z.image),
- sinh!(z.real) * sin!(z.image))
+ Complex(cosh!(z.real) * cos!(z.imag),
+ sinh!(z.real) * sin!(z.imag))
end
end
@@ -129,7 +129,7 @@ module CMath
if z.real? and z >= -1 and z <= 1
asin!(z)
else
- -1.0.im * log(1.0.im * z + sqrt(1.0 - z * z))
+ Complex(0, -1.0) * log(Complex(0, 1.0) * z + sqrt(1.0 - z * z))
end
end
@@ -137,7 +137,7 @@ module CMath
if z.real? and z >= -1 and z <= 1
acos!(z)
else
- -1.0.im * log(z + 1.0.im * sqrt(1.0 - z * z))
+ Complex(0, -1.0) * log(z + Complex(0, 1.0) * sqrt(1.0 - z * z))
end
end
@@ -145,7 +145,7 @@ module CMath
if z.real?
atan!(z)
else
- 1.0.im * log((1.0.im + z) / (1.0.im - z)) / 2.0
+ Complex(0, 1.0) * log((Complex(0, 1.0) + z) / (Complex(0, 1.0) - z)) / 2.0
end
end
@@ -153,7 +153,7 @@ module CMath
if y.real? and x.real?
atan2!(y,x)
else
- -1.0.im * log((x + 1.0.im * y) / sqrt(x * x + y * y))
+ Complex(0, -1.0) * log((x + Complex(0, 1.0) * y) / sqrt(x * x + y * y))
end
end
diff --git a/lib/complex.rb b/lib/complex.rb
index 70e168e912..c03ee63c3e 100644
--- a/lib/complex.rb
+++ b/lib/complex.rb
@@ -10,3 +10,9 @@ def Complex.generic? (other)
other.kind_of?(Float) ||
other.kind_of?(Rational)
end
+
+class Complex
+
+ alias image imag
+
+end
diff --git a/lib/mathn.rb b/lib/mathn.rb
index b29f994ac9..e918608b0d 100644
--- a/lib/mathn.rb
+++ b/lib/mathn.rb
@@ -37,7 +37,7 @@ class Rational
if other.kind_of?(Rational)
other2 = other
if self < 0
- return Complex.__send__(:new!, self, 0) ** other
+ return Complex(self, 0.0) ** other
elsif other == 0
return Rational(1,1)
elsif self == 0
@@ -99,7 +99,7 @@ module Math
remove_method(:sqrt)
def sqrt(a)
if a.kind_of?(Complex)
- abs = sqrt(a.real*a.real + a.image*a.image)
+ abs = sqrt(a.real*a.real + a.imag*a.imag)
# if not abs.kind_of?(Rational)
# return a**Rational(1,2)
# end
@@ -108,7 +108,7 @@ module Math
# if !(x.kind_of?(Rational) and y.kind_of?(Rational))
# return a**Rational(1,2)
# end
- if a.image >= 0
+ if a.imag >= 0
Complex(x, y)
else
Complex(x, -y)