mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
2d302dfd40
commit
8f40b26581
8 changed files with 327 additions and 309 deletions
34
lib/cmath.rb
34
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue