1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* math.c (math_log): should check argc.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19448 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2008-09-21 12:53:40 +00:00
parent 83b381752e
commit bdf81563bf
3 changed files with 6 additions and 1 deletions

View file

@ -1,3 +1,7 @@
Sun Sep 21 21:52:41 2008 Tadayoshi Funaba <tadf@dotrb.org>
* math.c (math_log): should check argc.
Sun Sep 21 21:20:24 2008 Tadayoshi Funaba <tadf@dotrb.org> Sun Sep 21 21:20:24 2008 Tadayoshi Funaba <tadf@dotrb.org>
* complex.c: added two macros. * complex.c: added two macros.

2
math.c
View file

@ -353,7 +353,7 @@ math_log(int argc, VALUE *argv)
Need_Float(x); Need_Float(x);
errno = 0; errno = 0;
d = log(RFLOAT_VALUE(x)); d = log(RFLOAT_VALUE(x));
if (!NIL_P(base)) { if (argc == 2) {
Need_Float(base); Need_Float(base);
d /= log(RFLOAT_VALUE(base)); d /= log(RFLOAT_VALUE(base));
} }

View file

@ -113,6 +113,7 @@ class TestMath < Test::Unit::TestCase
assert_equal(1.0/0, Math.log(1.0/0)) 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(0) }
assert_raise(Errno::EDOM, Errno::ERANGE) { Math.log(-1) } assert_raise(Errno::EDOM, Errno::ERANGE) { Math.log(-1) }
assert_raise(TypeError) { Math.log(1,nil) }
end end
def test_log2 def test_log2