From 8e4196fa402858cc561021579be3653b24ec6348 Mon Sep 17 00:00:00 2001 From: gogotanaka Date: Sat, 8 Nov 2014 03:26:39 -0800 Subject: [PATCH 2/3] raise error when more than 3 args passed --- lib/cmath.rb | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/cmath.rb b/lib/cmath.rb index aee577c..4a670d7 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=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 - -- 1.9.3 (Apple Git-50)