* rational.c (nurat_div): divided by float zero should be

infinity.  [ruby-core:31626]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28886 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-08-06 11:12:35 +00:00
Родитель 8aa6059dbf
Коммит edd4332a38
3 изменённых файлов: 10 добавлений и 1 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Fri Aug 6 20:12:28 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* rational.c (nurat_div): divided by float zero should be
infinity. [ruby-core:31626]
Fri Aug 6 18:59:23 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (realpath_rec): rb_str_modify depends on the length, so

Просмотреть файл

@ -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));
}
}

Просмотреть файл

@ -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))