summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-22 12:27:54 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-22 12:27:54 +0000
commit8f40b265811a23eef5b8c9e0b677b7d15cd6ea45 (patch)
tree87500a4a23ee3748c74aff1f750eacef665b9cca /lib
parent2d302dfd40ee9a4b3183415b19dbc22cf9106ba3 (diff)
* complex.c (nucomp_div): now behaves as quo.
* complex.c (nucomp_s_generic_p): has been removed. * complex.c (nucomp_to_s): adopts new form. * complex.c (nucomp_inspect): ditto. * complex.c (string_to_c_internal): ditto and supports polar form. * complex.c (rb_complex_polar): new. * rational.c (nurat_to_s): did not canonicalize. * rational.c (nurat_inspect): adopts new form. * rational.c (string_to_r_internal): ditto. * include/ruby/intern.h: added a declaration. * lib/complex.rb: added an obsolate class method. * lib/cmath.rb: use scalar? instead of generic?. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/cmath.rb34
-rw-r--r--lib/complex.rb6
2 files changed, 23 insertions, 17 deletions
diff --git a/lib/cmath.rb b/lib/cmath.rb
index 158da41..5599587 100644
--- a/lib/cmath.rb
+++ b/lib/cmath.rb
@@ -25,7 +25,7 @@ module CMath
alias atanh! atanh
def exp(z)
- if Complex.generic?(z)
+ if z.scalar?
exp!(z)
else
Complex(exp!(z.real) * cos!(z.image),
@@ -35,7 +35,7 @@ module CMath
def log(*args)
z, b = args
- if Complex.generic?(z) and z >= 0 and (b.nil? or b >= 0)
+ if z.scalar? and z >= 0 and (b.nil? or b >= 0)
log!(*args)
else
r, theta = z.polar
@@ -48,7 +48,7 @@ module CMath
end
def log10(z)
- if Complex.generic?(z)
+ if z.scalar?
log10!(z)
else
log(z) / log!(10)
@@ -56,7 +56,7 @@ module CMath
end
def sqrt(z)
- if Complex.generic?(z)
+ if z.scalar?
if z >= 0
sqrt!(z)
else
@@ -74,7 +74,7 @@ module CMath
end
def sin(z)
- if Complex.generic?(z)
+ if z.scalar?
sin!(z)
else
Complex(sin!(z.real) * cosh!(z.image),
@@ -83,7 +83,7 @@ module CMath
end
def cos(z)
- if Complex.generic?(z)
+ if z.scalar?
cos!(z)
else
Complex(cos!(z.real) * cosh!(z.image),
@@ -92,7 +92,7 @@ module CMath
end
def tan(z)
- if Complex.generic?(z)
+ if z.scalar?
tan!(z)
else
sin(z)/cos(z)
@@ -100,7 +100,7 @@ module CMath
end
def sinh(z)
- if Complex.generic?(z)
+ if z.scalar?
sinh!(z)
else
Complex(sinh!(z.real) * cos!(z.image),
@@ -109,7 +109,7 @@ module CMath
end
def cosh(z)
- if Complex.generic?(z)
+ if z.scalar?
cosh!(z)
else
Complex(cosh!(z.real) * cos!(z.image),
@@ -118,7 +118,7 @@ module CMath
end
def tanh(z)
- if Complex.generic?(z)
+ if z.scalar?
tanh!(z)
else
sinh(z) / cosh(z)
@@ -126,7 +126,7 @@ module CMath
end
def asin(z)
- if Complex.generic?(z) and z >= -1 and z <= 1
+ if z.scalar? and z >= -1 and z <= 1
asin!(z)
else
-1.0.im * log(1.0.im * z + sqrt(1.0 - z * z))
@@ -134,7 +134,7 @@ module CMath
end
def acos(z)
- if Complex.generic?(z) and z >= -1 and z <= 1
+ if z.scalar? and z >= -1 and z <= 1
acos!(z)
else
-1.0.im * log(z + 1.0.im * sqrt(1.0 - z * z))
@@ -142,7 +142,7 @@ module CMath
end
def atan(z)
- if Complex.generic?(z)
+ if z.scalar?
atan!(z)
else
1.0.im * log((1.0.im + z) / (1.0.im - z)) / 2.0
@@ -150,7 +150,7 @@ module CMath
end
def atan2(y,x)
- if Complex.generic?(y) and Complex.generic?(x)
+ if y.scalar? and x.scalar?
atan2!(y,x)
else
-1.0.im * log((x + 1.0.im * y) / sqrt(x * x + y * y))
@@ -158,7 +158,7 @@ module CMath
end
def acosh(z)
- if Complex.generic?(z) and z >= 1
+ if z.scalar? and z >= 1
acosh!(z)
else
log(z + sqrt(z * z - 1.0))
@@ -166,7 +166,7 @@ module CMath
end
def asinh(z)
- if Complex.generic?(z)
+ if z.scalar?
asinh!(z)
else
log(z + sqrt(1.0 + z * z))
@@ -174,7 +174,7 @@ module CMath
end
def atanh(z)
- if Complex.generic?(z) and z >= -1 and z <= 1
+ if z.scalar? and z >= -1 and z <= 1
atanh!(z)
else
log((1.0 + z) / (1.0 - z)) / 2.0
diff --git a/lib/complex.rb b/lib/complex.rb
index 0e88dd5..1845f30 100644
--- a/lib/complex.rb
+++ b/lib/complex.rb
@@ -2,3 +2,9 @@ require 'cmath'
Object.instance_eval{remove_const :Math}
Math = CMath
+
+def Complex.generic? (other)
+ other.kind_of?(Integer) ||
+ other.kind_of?(Float) ||
+ other.kind_of?(Rational)
+end