ruby-changes:37648
From: gogotanaka <ko1@a...>
Date: Wed, 25 Feb 2015 08:53:35 +0900 (JST)
Subject: [ruby-changes:37648] gogotanaka:r49729 (trunk): * lib/cmath.rb (log): raise ArgumentError when more than 2 arguments
gogotanaka 2015-02-25 08:53:21 +0900 (Wed, 25 Feb 2015) New Revision: 49729 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49729 Log: * lib/cmath.rb (log): raise ArgumentError when more than 2 arguments are passed. [ruby-core:66143] [Bug #10487] Modified files: trunk/ChangeLog trunk/lib/cmath.rb trunk/test/ruby/test_complex.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 49728) +++ ChangeLog (revision 49729) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Feb 25 08:49:12 2015 Kazuki Tanaka <gogotanaka@r...> + + * 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@r...> * test/ruby/test_math.rb: Use assert_infinity instead of assert_equal(1.0/0, ...). Index: lib/cmath.rb =================================================================== --- lib/cmath.rb (revision 49728) +++ lib/cmath.rb (revision 49729) @@ -66,20 +66,12 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L66 # 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) - else - a = Complex(log!(z.abs), z.arg) - if b - a /= log(b) - end - a + if z.real? && z >= 0 && b >= 0 + log!(z, b) + else + Complex(log!(z.abs), z.arg) / log(b) end rescue NoMethodError handle_no_method_error @@ -397,4 +389,3 @@ module CMath https://github.com/ruby/ruby/blob/trunk/lib/cmath.rb#L389 module_function :handle_no_method_error end - Index: test/ruby/test_complex.rb =================================================================== --- test/ruby/test_complex.rb (revision 49728) +++ test/ruby/test_complex.rb (revision 49729) @@ -950,9 +950,9 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L950 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/