ruby-changes:40636
From: ngoto <ko1@a...>
Date: Sun, 22 Nov 2015 22:09:53 +0900 (JST)
Subject: [ruby-changes:40636] ngoto:r52715 (trunk): * lib/cmath.rb: methods which has suffix '!' are now deprecated.
ngoto 2015-11-22 22:09:41 +0900 (Sun, 22 Nov 2015) New Revision: 52715 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52715 Log: * 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] Modified files: trunk/ChangeLog trunk/lib/cmath.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 52714) +++ ChangeLog (revision 52715) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Nov 22 21:58:09 2015 Naohisa Goto <ngotogenome@g...> + + * 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@r...> * ext/openssl/ossl.c: fix brew command for installation of openssl. Index: lib/cmath.rb =================================================================== --- lib/cmath.rb (revision 52714) +++ lib/cmath.rb (revision 52715) @@ -23,29 +23,36 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L23 include Math - alias exp! exp - alias log! log - alias log2! log2 - alias log10! log10 - alias sqrt! sqrt - alias cbrt! cbrt - - alias sin! sin - alias cos! cos - alias tan! tan - - alias sinh! sinh - alias cosh! cosh - alias tanh! tanh - - alias asin! asin - alias acos! acos - alias atan! atan - alias atan2! atan2 - - alias asinh! asinh - alias acosh! acosh - alias atanh! atanh + # Backup of Math is needed because mathn.rb replaces Math with CMath. + RealMath = Math # :nodoc: + private_constant :RealMath + + %w[ + exp + log + log2 + log10 + sqrt + cbrt + sin + cos + tan + sinh + cosh + tanh + asin + acos + 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 @@ -54,11 +61,11 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L61 def exp(z) begin if z.real? - exp!(z) + RealMath.exp(z) else - ere = exp!(z.real) - Complex(ere * cos!(z.imag), - ere * sin!(z.imag)) + ere = RealMath.exp(z.real) + Complex(ere * RealMath.cos(z.imag), + ere * RealMath.sin(z.imag)) end rescue NoMethodError handle_no_method_error @@ -74,9 +81,9 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L81 def log(z, b=::Math::E) begin if z.real? && z >= 0 && b >= 0 - log!(z, b) + RealMath.log(z, b) else - Complex(log!(z.abs), z.arg) / log(b) + Complex(RealMath.log(z.abs), z.arg) / log(b) end rescue NoMethodError handle_no_method_error @@ -90,9 +97,9 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L97 def log2(z) begin if z.real? and z >= 0 - log2!(z) + RealMath.log2(z) else - log(z) / log!(2) + log(z) / RealMath.log(2) end rescue NoMethodError handle_no_method_error @@ -106,9 +113,9 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L113 def log10(z) begin if z.real? and z >= 0 - log10!(z) + RealMath.log10(z) else - log(z) / log!(10) + log(z) / RealMath.log(10) end rescue NoMethodError handle_no_method_error @@ -123,9 +130,9 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L130 begin if z.real? if z < 0 - Complex(0, sqrt!(-z)) + Complex(0, RealMath.sqrt(-z)) else - sqrt!(z) + RealMath.sqrt(z) end else if z.imag < 0 || @@ -134,7 +141,7 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L141 else r = z.abs 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 rescue NoMethodError @@ -157,10 +164,10 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L164 def sin(z) begin if z.real? - sin!(z) + RealMath.sin(z) else - Complex(sin!(z.real) * cosh!(z.imag), - cos!(z.real) * sinh!(z.imag)) + Complex(RealMath.sin(z.real) * RealMath.cosh(z.imag), + RealMath.cos(z.real) * RealMath.sinh(z.imag)) end rescue NoMethodError handle_no_method_error @@ -174,10 +181,10 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L181 def cos(z) begin if z.real? - cos!(z) + RealMath.cos(z) else - Complex(cos!(z.real) * cosh!(z.imag), - -sin!(z.real) * sinh!(z.imag)) + Complex(RealMath.cos(z.real) * RealMath.cosh(z.imag), + -RealMath.sin(z.real) * RealMath.sinh(z.imag)) end rescue NoMethodError handle_no_method_error @@ -191,7 +198,7 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L198 def tan(z) begin if z.real? - tan!(z) + RealMath.tan(z) else sin(z) / cos(z) end @@ -207,10 +214,10 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L214 def sinh(z) begin if z.real? - sinh!(z) + RealMath.sinh(z) else - Complex(sinh!(z.real) * cos!(z.imag), - cosh!(z.real) * sin!(z.imag)) + Complex(RealMath.sinh(z.real) * RealMath.cos(z.imag), + RealMath.cosh(z.real) * RealMath.sin(z.imag)) end rescue NoMethodError handle_no_method_error @@ -224,10 +231,10 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L231 def cosh(z) begin if z.real? - cosh!(z) + RealMath.cosh(z) else - Complex(cosh!(z.real) * cos!(z.imag), - sinh!(z.real) * sin!(z.imag)) + Complex(RealMath.cosh(z.real) * RealMath.cos(z.imag), + RealMath.sinh(z.real) * RealMath.sin(z.imag)) end rescue NoMethodError handle_no_method_error @@ -241,7 +248,7 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L248 def tanh(z) begin if z.real? - tanh!(z) + RealMath.tanh(z) else sinh(z) / cosh(z) end @@ -257,7 +264,7 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L264 def asin(z) begin if z.real? and z >= -1 and z <= 1 - asin!(z) + RealMath.asin(z) else (-1.0).i * log(1.0.i * z + sqrt(1.0 - z * z)) end @@ -273,7 +280,7 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L280 def acos(z) begin if z.real? and z >= -1 and z <= 1 - acos!(z) + RealMath.acos(z) else (-1.0).i * log(z + 1.0.i * sqrt(1.0 - z * z)) end @@ -289,7 +296,7 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L296 def atan(z) begin if z.real? - atan!(z) + RealMath.atan(z) else 1.0.i * log((1.0.i + z) / (1.0.i - z)) / 2.0 end @@ -306,7 +313,7 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L313 def atan2(y,x) begin if y.real? and x.real? - atan2!(y,x) + RealMath.atan2(y,x) else (-1.0).i * log((x + 1.0.i * y) / sqrt(x * x + y * y)) end @@ -322,7 +329,7 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L329 def asinh(z) begin if z.real? - asinh!(z) + RealMath.asinh(z) else log(z + sqrt(1.0 + z * z)) end @@ -338,7 +345,7 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L345 def acosh(z) begin if z.real? and z >= 1 - acosh!(z) + RealMath.acosh(z) else log(z + sqrt(z * z - 1.0)) end @@ -354,7 +361,7 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L361 def atanh(z) begin if z.real? and z >= -1 and z <= 1 - atanh!(z) + RealMath.atanh(z) else log((1.0 + z) / (1.0 - z)) / 2.0 end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/