* lib/cmath.rb: methods which has suffix '!' are now deprecated.

Re-apply r52469 made by Kazuki Tanaka, with fixing bug about
  mathn.rb compatibility. [ruby-core:68528] [Feature #10974]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ngoto 2015-11-22 13:09:41 +00:00
Родитель 81a6bd50c2
Коммит d71ead259e
2 изменённых файлов: 69 добавлений и 56 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Sun Nov 22 21:58:09 2015 Naohisa Goto <ngotogenome@gmail.com>
* lib/cmath.rb: methods which has suffix '!' are now deprecated.
Re-apply r52469 made by Kazuki Tanaka, with fixing bug about
mathn.rb compatibility. [ruby-core:68528] [Feature #10974]
Sun Nov 22 19:36:51 2015 SHIBATA Hiroshi <hsbt@ruby-lang.org> Sun Nov 22 19:36:51 2015 SHIBATA Hiroshi <hsbt@ruby-lang.org>
* ext/openssl/ossl.c: fix brew command for installation of openssl. * ext/openssl/ossl.c: fix brew command for installation of openssl.

Просмотреть файл

@ -23,29 +23,36 @@ module CMath
include Math include Math
alias exp! exp # Backup of Math is needed because mathn.rb replaces Math with CMath.
alias log! log RealMath = Math # :nodoc:
alias log2! log2 private_constant :RealMath
alias log10! log10
alias sqrt! sqrt
alias cbrt! cbrt
alias sin! sin %w[
alias cos! cos exp
alias tan! tan log
log2
alias sinh! sinh log10
alias cosh! cosh sqrt
alias tanh! tanh cbrt
sin
alias asin! asin cos
alias acos! acos tan
alias atan! atan sinh
alias atan2! atan2 cosh
tanh
alias asinh! asinh asin
alias acosh! acosh acos
alias atanh! atanh atan
atan2
asinh
acosh
atanh
].each do |meth|
define_method(meth + '!') do |*args, &block|
warn("CMath##{meth}! is deprecated; use CMath##{meth} or Math##{meth}") if $VERBOSE
RealMath.send(meth, *args, &block)
end
end
## ##
# Math::E raised to the +z+ power # Math::E raised to the +z+ power
@ -54,11 +61,11 @@ module CMath
def exp(z) def exp(z)
begin begin
if z.real? if z.real?
exp!(z) RealMath.exp(z)
else else
ere = exp!(z.real) ere = RealMath.exp(z.real)
Complex(ere * cos!(z.imag), Complex(ere * RealMath.cos(z.imag),
ere * sin!(z.imag)) ere * RealMath.sin(z.imag))
end end
rescue NoMethodError rescue NoMethodError
handle_no_method_error handle_no_method_error
@ -74,9 +81,9 @@ module CMath
def log(z, b=::Math::E) def log(z, b=::Math::E)
begin begin
if z.real? && z >= 0 && b >= 0 if z.real? && z >= 0 && b >= 0
log!(z, b) RealMath.log(z, b)
else else
Complex(log!(z.abs), z.arg) / log(b) Complex(RealMath.log(z.abs), z.arg) / log(b)
end end
rescue NoMethodError rescue NoMethodError
handle_no_method_error handle_no_method_error
@ -90,9 +97,9 @@ module CMath
def log2(z) def log2(z)
begin begin
if z.real? and z >= 0 if z.real? and z >= 0
log2!(z) RealMath.log2(z)
else else
log(z) / log!(2) log(z) / RealMath.log(2)
end end
rescue NoMethodError rescue NoMethodError
handle_no_method_error handle_no_method_error
@ -106,9 +113,9 @@ module CMath
def log10(z) def log10(z)
begin begin
if z.real? and z >= 0 if z.real? and z >= 0
log10!(z) RealMath.log10(z)
else else
log(z) / log!(10) log(z) / RealMath.log(10)
end end
rescue NoMethodError rescue NoMethodError
handle_no_method_error handle_no_method_error
@ -123,9 +130,9 @@ module CMath
begin begin
if z.real? if z.real?
if z < 0 if z < 0
Complex(0, sqrt!(-z)) Complex(0, RealMath.sqrt(-z))
else else
sqrt!(z) RealMath.sqrt(z)
end end
else else
if z.imag < 0 || if z.imag < 0 ||
@ -134,7 +141,7 @@ module CMath
else else
r = z.abs r = z.abs
x = z.real x = z.real
Complex(sqrt!((r + x) / 2.0), sqrt!((r - x) / 2.0)) Complex(RealMath.sqrt((r + x) / 2.0), RealMath.sqrt((r - x) / 2.0))
end end
end end
rescue NoMethodError rescue NoMethodError
@ -157,10 +164,10 @@ module CMath
def sin(z) def sin(z)
begin begin
if z.real? if z.real?
sin!(z) RealMath.sin(z)
else else
Complex(sin!(z.real) * cosh!(z.imag), Complex(RealMath.sin(z.real) * RealMath.cosh(z.imag),
cos!(z.real) * sinh!(z.imag)) RealMath.cos(z.real) * RealMath.sinh(z.imag))
end end
rescue NoMethodError rescue NoMethodError
handle_no_method_error handle_no_method_error
@ -174,10 +181,10 @@ module CMath
def cos(z) def cos(z)
begin begin
if z.real? if z.real?
cos!(z) RealMath.cos(z)
else else
Complex(cos!(z.real) * cosh!(z.imag), Complex(RealMath.cos(z.real) * RealMath.cosh(z.imag),
-sin!(z.real) * sinh!(z.imag)) -RealMath.sin(z.real) * RealMath.sinh(z.imag))
end end
rescue NoMethodError rescue NoMethodError
handle_no_method_error handle_no_method_error
@ -191,7 +198,7 @@ module CMath
def tan(z) def tan(z)
begin begin
if z.real? if z.real?
tan!(z) RealMath.tan(z)
else else
sin(z) / cos(z) sin(z) / cos(z)
end end
@ -207,10 +214,10 @@ module CMath
def sinh(z) def sinh(z)
begin begin
if z.real? if z.real?
sinh!(z) RealMath.sinh(z)
else else
Complex(sinh!(z.real) * cos!(z.imag), Complex(RealMath.sinh(z.real) * RealMath.cos(z.imag),
cosh!(z.real) * sin!(z.imag)) RealMath.cosh(z.real) * RealMath.sin(z.imag))
end end
rescue NoMethodError rescue NoMethodError
handle_no_method_error handle_no_method_error
@ -224,10 +231,10 @@ module CMath
def cosh(z) def cosh(z)
begin begin
if z.real? if z.real?
cosh!(z) RealMath.cosh(z)
else else
Complex(cosh!(z.real) * cos!(z.imag), Complex(RealMath.cosh(z.real) * RealMath.cos(z.imag),
sinh!(z.real) * sin!(z.imag)) RealMath.sinh(z.real) * RealMath.sin(z.imag))
end end
rescue NoMethodError rescue NoMethodError
handle_no_method_error handle_no_method_error
@ -241,7 +248,7 @@ module CMath
def tanh(z) def tanh(z)
begin begin
if z.real? if z.real?
tanh!(z) RealMath.tanh(z)
else else
sinh(z) / cosh(z) sinh(z) / cosh(z)
end end
@ -257,7 +264,7 @@ module CMath
def asin(z) def asin(z)
begin begin
if z.real? and z >= -1 and z <= 1 if z.real? and z >= -1 and z <= 1
asin!(z) RealMath.asin(z)
else else
(-1.0).i * log(1.0.i * z + sqrt(1.0 - z * z)) (-1.0).i * log(1.0.i * z + sqrt(1.0 - z * z))
end end
@ -273,7 +280,7 @@ module CMath
def acos(z) def acos(z)
begin begin
if z.real? and z >= -1 and z <= 1 if z.real? and z >= -1 and z <= 1
acos!(z) RealMath.acos(z)
else else
(-1.0).i * log(z + 1.0.i * sqrt(1.0 - z * z)) (-1.0).i * log(z + 1.0.i * sqrt(1.0 - z * z))
end end
@ -289,7 +296,7 @@ module CMath
def atan(z) def atan(z)
begin begin
if z.real? if z.real?
atan!(z) RealMath.atan(z)
else else
1.0.i * log((1.0.i + z) / (1.0.i - z)) / 2.0 1.0.i * log((1.0.i + z) / (1.0.i - z)) / 2.0
end end
@ -306,7 +313,7 @@ module CMath
def atan2(y,x) def atan2(y,x)
begin begin
if y.real? and x.real? if y.real? and x.real?
atan2!(y,x) RealMath.atan2(y,x)
else else
(-1.0).i * log((x + 1.0.i * y) / sqrt(x * x + y * y)) (-1.0).i * log((x + 1.0.i * y) / sqrt(x * x + y * y))
end end
@ -322,7 +329,7 @@ module CMath
def asinh(z) def asinh(z)
begin begin
if z.real? if z.real?
asinh!(z) RealMath.asinh(z)
else else
log(z + sqrt(1.0 + z * z)) log(z + sqrt(1.0 + z * z))
end end
@ -338,7 +345,7 @@ module CMath
def acosh(z) def acosh(z)
begin begin
if z.real? and z >= 1 if z.real? and z >= 1
acosh!(z) RealMath.acosh(z)
else else
log(z + sqrt(z * z - 1.0)) log(z + sqrt(z * z - 1.0))
end end
@ -354,7 +361,7 @@ module CMath
def atanh(z) def atanh(z)
begin begin
if z.real? and z >= -1 and z <= 1 if z.real? and z >= -1 and z <= 1
atanh!(z) RealMath.atanh(z)
else else
log((1.0 + z) / (1.0 - z)) / 2.0 log((1.0 + z) / (1.0 - z)) / 2.0
end end