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

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-08-06 11:13:48 +00:00
parent edd4332a38
commit cba4d05785
3 changed files with 7 additions and 9 deletions

View file

@ -1,4 +1,6 @@
Fri Aug 6 20:12:28 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
Fri Aug 6 20:13:42 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* rational.c (nurat_div): divided by infinity should be zero.
* rational.c (nurat_div): divided by float zero should be
infinity. [ruby-core:31626]

View file

@ -874,14 +874,7 @@ nurat_div(VALUE self, VALUE other)
get_dat1(self);
if (isnan(x)) return DBL2NUM(NAN);
if (isinf(x)) {
if (RTEST(f_negative_p(dat->num)) == (x < 0)) {
return DBL2NUM(INFINITY);
}
else {
return DBL2NUM(-INFINITY);
}
}
if (isinf(x)) return INT2FIX(0);
if (x != 0.0 && modf(x, &den) == 0.0) {
return rb_rational_raw2(dat->num, f_mul(rb_dbl2big(den), dat->den));
}

View file

@ -298,6 +298,7 @@ class Rational_Test < Test::Unit::TestCase
assert_raise(ZeroDivisionError){Rational(1, 3) / 0}
assert_raise(ZeroDivisionError){Rational(1, 3) / Rational(0)}
assert_equal(0, Rational(1, 3) / Float::INFINITY)
assert((Rational(1, 3) / 0.0).infinite?, '[ruby-core:31626]')
end
@ -548,6 +549,7 @@ class Rational_Test < Test::Unit::TestCase
assert_equal(0.25, c.fdiv(2))
assert_equal(0.25, c.fdiv(2.0))
assert_equal(0, c.fdiv(Float::INFINITY))
assert(c.fdiv(0).infinite?, '[ruby-core:31626]')
end
@ -1070,6 +1072,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_equal(0, Rational(1,2).quo(Float::INFINITY))
assert(Rational(1,2).quo(0.0).infinite?, '[ruby-core:31626]')
assert_equal(0.5, 1.fdiv(2))