aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/cmath.rb17
-rw-r--r--test/ruby/test_complex.rb6
3 files changed, 12 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 0a5e17ec2f..40aa704235 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Tue Feb 25 08:49:12 2015 Kazuki Tanaka <gogotanaka@ruby-lang.org>
+
+ * lib/cmath.rb (log): raise ArgumentError when more than 2 arguments
+ are passed. [ruby-core:66143] [Bug #10487]
+
Tue Feb 25 02:15:17 2015 Kazuki Tanaka <gogotanaka@ruby-lang.org>
* test/ruby/test_math.rb: Use assert_infinity instead of assert_equal(1.0/0, ...).
diff --git a/lib/cmath.rb b/lib/cmath.rb
index aee577c97c..e0c9139f8f 100644
--- a/lib/cmath.rb
+++ b/lib/cmath.rb
@@ -66,20 +66,12 @@ module CMath
# it will be the base of logarithm.
#
# log(Complex(0,0)) #=> -Infinity+0.0i
- def log(*args)
+ def log(z, b=::Math::E)
begin
- z, b = args
- unless b.nil? || b.kind_of?(Numeric)
- raise TypeError, "Numeric Number required"
- end
- if z.real? and z >= 0 and (b.nil? or b >= 0)
- log!(*args)
+ if z.real? && z >= 0 && b >= 0
+ log!(z, b)
else
- a = Complex(log!(z.abs), z.arg)
- if b
- a /= log(b)
- end
- a
+ Complex(log!(z.abs), z.arg) / log(b)
end
rescue NoMethodError
handle_no_method_error
@@ -397,4 +389,3 @@ module CMath
module_function :handle_no_method_error
end
-
diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb
index 3625eb97a5..beccc8e4f3 100644
--- a/test/ruby/test_complex.rb
+++ b/test/ruby/test_complex.rb
@@ -950,9 +950,9 @@ class Complex_Test < Test::Unit::TestCase
assert_in_delta(0.804, c.real, 0.001)
assert_in_delta(1.107, c.imag, 0.001)
- c = CMath.log(Complex(1, 2), Math::E)
- assert_in_delta(0.804, c.real, 0.001)
- assert_in_delta(1.107, c.imag, 0.001)
+ c = CMath.log(Complex(1, 2), Math::E**2)
+ assert_in_delta(0.402, c.real, 0.001)
+ assert_in_delta(0.5535, c.imag, 0.001)
c = CMath.log(-1)
assert_in_delta(0.0, c.real, 0.001)