diff --git a/ChangeLog b/ChangeLog index a093f5aced..bc577b284e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun Sep 21 21:52:41 2008 Tadayoshi Funaba + + * math.c (math_log): should check argc. + Sun Sep 21 21:20:24 2008 Tadayoshi Funaba * complex.c: added two macros. diff --git a/math.c b/math.c index ac0d4c1fe7..340014b624 100644 --- a/math.c +++ b/math.c @@ -353,7 +353,7 @@ math_log(int argc, VALUE *argv) Need_Float(x); errno = 0; d = log(RFLOAT_VALUE(x)); - if (!NIL_P(base)) { + if (argc == 2) { Need_Float(base); d /= log(RFLOAT_VALUE(base)); } diff --git a/test/ruby/test_math.rb b/test/ruby/test_math.rb index 55f354664c..d4dbf9dbf0 100644 --- a/test/ruby/test_math.rb +++ b/test/ruby/test_math.rb @@ -113,6 +113,7 @@ class TestMath < Test::Unit::TestCase assert_equal(1.0/0, Math.log(1.0/0)) assert_raise(Errno::EDOM, Errno::ERANGE) { Math.log(0) } assert_raise(Errno::EDOM, Errno::ERANGE) { Math.log(-1) } + assert_raise(TypeError) { Math.log(1,nil) } end def test_log2