summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-06 11:13:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-06 11:13:48 +0000
commitcba4d057853fc9d2dfe536a391d191d40cd03180 (patch)
treef1f19c86a4202480b4233912c8c187771b72f06b
parentedd4332a3803fa30b4624371c1cc37fe75d19ff4 (diff)
* 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
-rw-r--r--ChangeLog4
-rw-r--r--rational.c9
-rw-r--r--test/ruby/test_rational.rb3
3 files changed, 7 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index c5fcc2f..01a0d0e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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]
diff --git a/rational.c b/rational.c
index d732f8d..085f914 100644
--- a/rational.c
+++ b/rational.c
@@ -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));
}
diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb
index 4680a79..cf88617 100644
--- a/test/ruby/test_rational.rb
+++ b/test/ruby/test_rational.rb
@@ -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))