Skip to content

Commit

Permalink
Revert r52469
Browse files Browse the repository at this point in the history
"* lib/cmath.rb: methods which has suffix '!' are now deprecated."
It breaks rubyspec:
http://rubyci.s3.amazonaws.com/ubuntu1510/ruby-trunk/log/20151106T153002Z.fail.html.gz

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52471 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nurse committed Nov 6, 2015
1 parent 10ef802 commit e48bf65
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 68 deletions.
5 changes: 0 additions & 5 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
Sat Nov 7 00:03:50 2015 Kazuki Tanaka <gogotanaka@ruby-lang.org>

* lib/cmath.rb: methods which has suffix '!' are now deprecated.
[ruby-core:68528] [Feature #10974]

Fri Nov 6 23:13:53 2015 Kazuki Tanaka <gogotanaka@ruby-lang.org>

* array.c: clarifies Array#reject! documentation.
Expand Down
3 changes: 0 additions & 3 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ with all sufficient information, see the ChangeLog file.
* lib/matrix.rb
* Add Vector#round. https://github.com/ruby/ruby/pull/802

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

* ext/coverage/coverage.c
* Coverage.peek_result: new method to allow coverage to be captured without
stopping the coverage tool.
Expand Down
117 changes: 57 additions & 60 deletions lib/cmath.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,29 @@ module CMath

include Math

%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
Math.send(meth, *args, &block)
end
end
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

##
# Math::E raised to the +z+ power
Expand All @@ -57,11 +54,11 @@ module CMath
def exp(z)
begin
if z.real?
Math.exp(z)
exp!(z)
else
ere = Math.exp(z.real)
Complex(ere * Math.cos(z.imag),
ere * Math.sin(z.imag))
ere = exp!(z.real)
Complex(ere * cos!(z.imag),
ere * sin!(z.imag))
end
rescue NoMethodError
handle_no_method_error
Expand All @@ -77,9 +74,9 @@ def exp(z)
def log(z, b=::Math::E)
begin
if z.real? && z >= 0 && b >= 0
Math.log(z, b)
log!(z, b)
else
Complex(Math.log(z.abs), z.arg) / log(b)
Complex(log!(z.abs), z.arg) / log(b)
end
rescue NoMethodError
handle_no_method_error
Expand All @@ -93,9 +90,9 @@ def log(z, b=::Math::E)
def log2(z)
begin
if z.real? and z >= 0
Math.log2(z)
log2!(z)
else
log(z) / Math.log(2)
log(z) / log!(2)
end
rescue NoMethodError
handle_no_method_error
Expand All @@ -109,9 +106,9 @@ def log2(z)
def log10(z)
begin
if z.real? and z >= 0
Math.log10(z)
log10!(z)
else
log(z) / Math.log(10)
log(z) / log!(10)
end
rescue NoMethodError
handle_no_method_error
Expand All @@ -126,9 +123,9 @@ def sqrt(z)
begin
if z.real?
if z < 0
Complex(0, Math.sqrt(-z))
Complex(0, sqrt!(-z))
else
Math.sqrt(z)
sqrt!(z)
end
else
if z.imag < 0 ||
Expand All @@ -137,7 +134,7 @@ def sqrt(z)
else
r = z.abs
x = z.real
Complex(Math.sqrt((r + x) / 2.0), Math.sqrt((r - x) / 2.0))
Complex(sqrt!((r + x) / 2.0), sqrt!((r - x) / 2.0))
end
end
rescue NoMethodError
Expand All @@ -160,10 +157,10 @@ def cbrt(z)
def sin(z)
begin
if z.real?
Math.sin(z)
sin!(z)
else
Complex(Math.sin(z.real) * Math.cosh(z.imag),
Math.cos(z.real) * Math.sinh(z.imag))
Complex(sin!(z.real) * cosh!(z.imag),
cos!(z.real) * sinh!(z.imag))
end
rescue NoMethodError
handle_no_method_error
Expand All @@ -177,10 +174,10 @@ def sin(z)
def cos(z)
begin
if z.real?
Math.cos(z)
cos!(z)
else
Complex(Math.cos(z.real) * Math.cosh(z.imag),
-Math.sin(z.real) * Math.sinh(z.imag))
Complex(cos!(z.real) * cosh!(z.imag),
-sin!(z.real) * sinh!(z.imag))
end
rescue NoMethodError
handle_no_method_error
Expand All @@ -194,7 +191,7 @@ def cos(z)
def tan(z)
begin
if z.real?
Math.tan(z)
tan!(z)
else
sin(z) / cos(z)
end
Expand All @@ -210,10 +207,10 @@ def tan(z)
def sinh(z)
begin
if z.real?
Math.sinh(z)
sinh!(z)
else
Complex(Math.sinh(z.real) * Math.cos(z.imag),
Math.cosh(z.real) * Math.sin(z.imag))
Complex(sinh!(z.real) * cos!(z.imag),
cosh!(z.real) * sin!(z.imag))
end
rescue NoMethodError
handle_no_method_error
Expand All @@ -227,10 +224,10 @@ def sinh(z)
def cosh(z)
begin
if z.real?
Math.cosh(z)
cosh!(z)
else
Complex(Math.cosh(z.real) * Math.cos(z.imag),
Math.sinh(z.real) * Math.sin(z.imag))
Complex(cosh!(z.real) * cos!(z.imag),
sinh!(z.real) * sin!(z.imag))
end
rescue NoMethodError
handle_no_method_error
Expand All @@ -244,7 +241,7 @@ def cosh(z)
def tanh(z)
begin
if z.real?
Math.tanh(z)
tanh!(z)
else
sinh(z) / cosh(z)
end
Expand All @@ -260,7 +257,7 @@ def tanh(z)
def asin(z)
begin
if z.real? and z >= -1 and z <= 1
Math.asin(z)
asin!(z)
else
(-1.0).i * log(1.0.i * z + sqrt(1.0 - z * z))
end
Expand All @@ -276,7 +273,7 @@ def asin(z)
def acos(z)
begin
if z.real? and z >= -1 and z <= 1
Math.acos(z)
acos!(z)
else
(-1.0).i * log(z + 1.0.i * sqrt(1.0 - z * z))
end
Expand All @@ -292,7 +289,7 @@ def acos(z)
def atan(z)
begin
if z.real?
Math.atan(z)
atan!(z)
else
1.0.i * log((1.0.i + z) / (1.0.i - z)) / 2.0
end
Expand All @@ -309,7 +306,7 @@ def atan(z)
def atan2(y,x)
begin
if y.real? and x.real?
Math.atan2(y,x)
atan2!(y,x)
else
(-1.0).i * log((x + 1.0.i * y) / sqrt(x * x + y * y))
end
Expand All @@ -325,7 +322,7 @@ def atan2(y,x)
def asinh(z)
begin
if z.real?
Math.asinh(z)
asinh!(z)
else
log(z + sqrt(1.0 + z * z))
end
Expand All @@ -341,7 +338,7 @@ def asinh(z)
def acosh(z)
begin
if z.real? and z >= 1
Math.acosh(z)
acosh!(z)
else
log(z + sqrt(z * z - 1.0))
end
Expand All @@ -357,7 +354,7 @@ def acosh(z)
def atanh(z)
begin
if z.real? and z >= -1 and z <= 1
Math.atanh(z)
atanh!(z)
else
log((1.0 + z) / (1.0 - z)) / 2.0
end
Expand Down

0 comments on commit e48bf65

Please sign in to comment.