diff --git a/ChangeLog b/ChangeLog index 5b03e712b6..c5fcc2fbb4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Aug 6 20:12:28 2010 Nobuyoshi Nakada + + * rational.c (nurat_div): divided by float zero should be + infinity. [ruby-core:31626] + Fri Aug 6 18:59:23 2010 Nobuyoshi Nakada * file.c (realpath_rec): rb_str_modify depends on the length, so diff --git a/rational.c b/rational.c index 6e3b39639d..d732f8d8a7 100644 --- a/rational.c +++ b/rational.c @@ -882,7 +882,7 @@ nurat_div(VALUE self, VALUE other) return DBL2NUM(-INFINITY); } } - if (modf(x, &den) == 0.0) { + if (x != 0.0 && modf(x, &den) == 0.0) { return rb_rational_raw2(dat->num, f_mul(rb_dbl2big(den), dat->den)); } } diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index 2f33ec2039..4680a79716 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -297,6 +297,8 @@ class Rational_Test < Test::Unit::TestCase assert_raise(ZeroDivisionError){Rational(1, 3) / 0} assert_raise(ZeroDivisionError){Rational(1, 3) / Rational(0)} + + assert((Rational(1, 3) / 0.0).infinite?, '[ruby-core:31626]') end def assert_eql(exp, act, *args) @@ -546,6 +548,7 @@ class Rational_Test < Test::Unit::TestCase assert_equal(0.25, c.fdiv(2)) assert_equal(0.25, c.fdiv(2.0)) + assert(c.fdiv(0).infinite?, '[ruby-core:31626]') end def test_expt @@ -1067,6 +1070,7 @@ class Rational_Test < Test::Unit::TestCase assert_equal(Rational(5000000000), 10000000000.quo(2)) assert_equal(0.5, 1.0.quo(2)) assert_equal(Rational(1,4), Rational(1,2).quo(2)) + assert(Rational(1,2).quo(0.0).infinite?, '[ruby-core:31626]') assert_equal(0.5, 1.fdiv(2)) assert_equal(5000000000.0, 10000000000.fdiv(2))