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

* bignum.c (rb_big_divide): raise ZeroDivisionError if divisor is

zero, as well as Fixnum.  [ruby-core:40429] [Bug #5490]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33536 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2011-10-27 07:10:53 +00:00
parent e344d8a483
commit 723038b0ba
3 changed files with 11 additions and 1 deletions

View file

@ -1,3 +1,8 @@
Thu Oct 27 16:10:46 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bignum.c (rb_big_divide): raise ZeroDivisionError if divisor is
zero, as well as Fixnum. [ruby-core:40429] [Bug #5490]
Thu Oct 27 14:56:22 2011 Nobuyoshi Nakada <nobu@ruby-lang.org> Thu Oct 27 14:56:22 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (RUBY_FUNC_ATTRIBUTE): unset temporary variable. * configure.in (RUBY_FUNC_ATTRIBUTE): unset temporary variable.

View file

@ -2774,7 +2774,9 @@ rb_big_divide(VALUE x, VALUE y, ID op)
case T_FLOAT: case T_FLOAT:
{ {
double div = rb_big2dbl(x) / RFLOAT_VALUE(y); double div, dy = RFLOAT_VALUE(y);
if (dy == 0.0) rb_num_zerodiv();
div = rb_big2dbl(x) / dy;
if (op == '/') { if (op == '/') {
return DBL2NUM(div); return DBL2NUM(div);
} }

View file

@ -272,6 +272,9 @@ class TestBignum < Test::Unit::TestCase
assert_equal(T32.to_f, T32 / 1.0) assert_equal(T32.to_f, T32 / 1.0)
assert_raise(TypeError) { T32 / "foo" } assert_raise(TypeError) { T32 / "foo" }
assert_equal(0x20000000, 0x40000001.div(2.0), "[ruby-dev:34553]") assert_equal(0x20000000, 0x40000001.div(2.0), "[ruby-dev:34553]")
bug5490 = '[ruby-core:40429]'
assert_raise(ZeroDivisionError, bug5490) {T1024.div(0)}
assert_raise(ZeroDivisionError, bug5490) {T1024.div(0.0)}
end end
def test_idiv def test_idiv