summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgogotanaka <gogotanaka@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-06 15:11:39 +0000
committergogotanaka <gogotanaka@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-06 15:11:39 +0000
commit74ae4ae2918c815345b9039af3af2a28b8399628 (patch)
tree906515f59efba13a11ffc8e5768c7beb0349f5b2
parent0765fcf8334b574ddf4d94c8be61797dab195dc4 (diff)
* lib/cmath.rb: methods which has suffix '!' are now deprecated.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--NEWS3
-rw-r--r--lib/cmath.rb117
3 files changed, 68 insertions, 57 deletions
diff --git a/ChangeLog b/ChangeLog
index 6aa1d6f..beca3a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+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.
diff --git a/NEWS b/NEWS
index cd3b548..89ab3f0 100644
--- a/NEWS
+++ b/NEWS
@@ -181,6 +181,9 @@ 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.
diff --git a/lib/cmath.rb b/lib/cmath.rb
index bd47f55..fbd13bc 100644
--- a/lib/cmath.rb
+++ b/lib/cmath.rb
@@ -23,29 +23,32 @@ module CMath
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
+ %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
##
# Math::E raised to the +z+ power
@@ -54,11 +57,11 @@ module CMath
def exp(z)
begin
if z.real?
- exp!(z)
+ Math.exp(z)
else
- ere = exp!(z.real)
- Complex(ere * cos!(z.imag),
- ere * sin!(z.imag))
+ ere = Math.exp(z.real)
+ Complex(ere * Math.cos(z.imag),
+ ere * Math.sin(z.imag))
end
rescue NoMethodError
handle_no_method_error
@@ -74,9 +77,9 @@ module CMath
def log(z, b=::Math::E)
begin
if z.real? && z >= 0 && b >= 0
- log!(z, b)
+ Math.log(z, b)
else
- Complex(log!(z.abs), z.arg) / log(b)
+ Complex(Math.log(z.abs), z.arg) / log(b)
end
rescue NoMethodError
handle_no_method_error
@@ -90,9 +93,9 @@ module CMath
def log2(z)
begin
if z.real? and z >= 0
- log2!(z)
+ Math.log2(z)
else
- log(z) / log!(2)
+ log(z) / Math.log(2)
end
rescue NoMethodError
handle_no_method_error
@@ -106,9 +109,9 @@ module CMath
def log10(z)
begin
if z.real? and z >= 0
- log10!(z)
+ Math.log10(z)
else
- log(z) / log!(10)
+ log(z) / Math.log(10)
end
rescue NoMethodError
handle_no_method_error
@@ -123,9 +126,9 @@ module CMath
begin
if z.real?
if z < 0
- Complex(0, sqrt!(-z))
+ Complex(0, Math.sqrt(-z))
else
- sqrt!(z)
+ Math.sqrt(z)
end
else
if z.imag < 0 ||
@@ -134,7 +137,7 @@ module CMath
else
r = z.abs
x = z.real
- Complex(sqrt!((r + x) / 2.0), sqrt!((r - x) / 2.0))
+ Complex(Math.sqrt((r + x) / 2.0), Math.sqrt((r - x) / 2.0))
end
end
rescue NoMethodError
@@ -157,10 +160,10 @@ module CMath
def sin(z)
begin
if z.real?
- sin!(z)
+ Math.sin(z)
else
- Complex(sin!(z.real) * cosh!(z.imag),
- cos!(z.real) * sinh!(z.imag))
+ Complex(Math.sin(z.real) * Math.cosh(z.imag),
+ Math.cos(z.real) * Math.sinh(z.imag))
end
rescue NoMethodError
handle_no_method_error
@@ -174,10 +177,10 @@ module CMath
def cos(z)
begin
if z.real?
- cos!(z)
+ Math.cos(z)
else
- Complex(cos!(z.real) * cosh!(z.imag),
- -sin!(z.real) * sinh!(z.imag))
+ Complex(Math.cos(z.real) * Math.cosh(z.imag),
+ -Math.sin(z.real) * Math.sinh(z.imag))
end
rescue NoMethodError
handle_no_method_error
@@ -191,7 +194,7 @@ module CMath
def tan(z)
begin
if z.real?
- tan!(z)
+ Math.tan(z)
else
sin(z) / cos(z)
end
@@ -207,10 +210,10 @@ module CMath
def sinh(z)
begin
if z.real?
- sinh!(z)
+ Math.sinh(z)
else
- Complex(sinh!(z.real) * cos!(z.imag),
- cosh!(z.real) * sin!(z.imag))
+ Complex(Math.sinh(z.real) * Math.cos(z.imag),
+ Math.cosh(z.real) * Math.sin(z.imag))
end
rescue NoMethodError
handle_no_method_error
@@ -224,10 +227,10 @@ module CMath
def cosh(z)
begin
if z.real?
- cosh!(z)
+ Math.cosh(z)
else
- Complex(cosh!(z.real) * cos!(z.imag),
- sinh!(z.real) * sin!(z.imag))
+ Complex(Math.cosh(z.real) * Math.cos(z.imag),
+ Math.sinh(z.real) * Math.sin(z.imag))
end
rescue NoMethodError
handle_no_method_error
@@ -241,7 +244,7 @@ module CMath
def tanh(z)
begin
if z.real?
- tanh!(z)
+ Math.tanh(z)
else
sinh(z) / cosh(z)
end
@@ -257,7 +260,7 @@ module CMath
def asin(z)
begin
if z.real? and z >= -1 and z <= 1
- asin!(z)
+ Math.asin(z)
else
(-1.0).i * log(1.0.i * z + sqrt(1.0 - z * z))
end
@@ -273,7 +276,7 @@ module CMath
def acos(z)
begin
if z.real? and z >= -1 and z <= 1
- acos!(z)
+ Math.acos(z)
else
(-1.0).i * log(z + 1.0.i * sqrt(1.0 - z * z))
end
@@ -289,7 +292,7 @@ module CMath
def atan(z)
begin
if z.real?
- atan!(z)
+ Math.atan(z)
else
1.0.i * log((1.0.i + z) / (1.0.i - z)) / 2.0
end
@@ -306,7 +309,7 @@ module CMath
def atan2(y,x)
begin
if y.real? and x.real?
- atan2!(y,x)
+ Math.atan2(y,x)
else
(-1.0).i * log((x + 1.0.i * y) / sqrt(x * x + y * y))
end
@@ -322,7 +325,7 @@ module CMath
def asinh(z)
begin
if z.real?
- asinh!(z)
+ Math.asinh(z)
else
log(z + sqrt(1.0 + z * z))
end
@@ -338,7 +341,7 @@ module CMath
def acosh(z)
begin
if z.real? and z >= 1
- acosh!(z)
+ Math.acosh(z)
else
log(z + sqrt(z * z - 1.0))
end
@@ -354,7 +357,7 @@ module CMath
def atanh(z)
begin
if z.real? and z >= -1 and z <= 1
- atanh!(z)
+ Math.atanh(z)
else
log((1.0 + z) / (1.0 - z)) / 2.0
end