summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-06 11:12:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-06 11:12:35 +0000
commitedd4332a3803fa30b4624371c1cc37fe75d19ff4 (patch)
treecc0f941631e7e4142554d8719cdd14c833df6114
parent8aa6059dbfcf840b9e7870ca9639194e707b05a0 (diff)
* 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
-rw-r--r--ChangeLog5
-rw-r--r--rational.c2
-rw-r--r--test/ruby/test_rational.rb4
3 files changed, 10 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 5b03e71..c5fcc2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/rational.c b/rational.c
index 6e3b396..d732f8d 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 2f33ec2..4680a79 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))