summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-06 01:04:11 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-06 01:04:11 +0000
commitfebc42d05c6b8a401fff2361bf03fe338eb4d1b0 (patch)
tree0f067d8458ad54561a41f7d19c330f3b73fcbf4d
parentb43d6331cbf218583ddd1db3a388e5b8d46362f7 (diff)
* numeric.c (num_quo): should return a Float for a Float argument.
[ruby-dev:44710] [Bug #5515] * test/ruby/test_fixnum.rb: Add an assertion for the above change. * test/ruby/test_bignum.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--numeric.c21
-rw-r--r--test/ruby/test_bignum.rb4
-rw-r--r--test/ruby/test_fixnum.rb1
4 files changed, 26 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 3afb96c9971..d54787449d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Thu Jun 6 09:41:00 2013 Kenta Murata <mrkn@cookpad.com>
+
+ * numeric.c (num_quo): should return a Float for a Float argument.
+ [ruby-dev:44710] [Bug #5515]
+
+ * test/ruby/test_fixnum.rb: Add an assertion for the above change.
+
+ * test/ruby/test_bignum.rb: ditto.
+
Thu Jun 6 00:59:44 2013 Masaya Tarui <tarui@ruby-lang.org>
* gc.c (gc_mark): get rid of pushing useless objests.
diff --git a/numeric.c b/numeric.c
index 89544dc7453..e8d2f9df25f 100644
--- a/numeric.c
+++ b/numeric.c
@@ -371,29 +371,34 @@ num_uminus(VALUE num)
/*
* call-seq:
- * num.quo(numeric) -> real
+ * num.fdiv(numeric) -> float
*
- * Returns most exact division (rational for integers, float for floats).
+ * Returns float division.
*/
static VALUE
-num_quo(VALUE x, VALUE y)
+num_fdiv(VALUE x, VALUE y)
{
- return rb_funcall(rb_rational_raw1(x), '/', 1, y);
+ return rb_funcall(rb_Float(x), '/', 1, y);
}
/*
* call-seq:
- * num.fdiv(numeric) -> float
+ * num.quo(int_or_rat) -> rat
+ * num.quo(flo) -> flo
*
- * Returns float division.
+ * Returns most exact division (rational for integers, float for floats).
*/
static VALUE
-num_fdiv(VALUE x, VALUE y)
+num_quo(VALUE x, VALUE y)
{
- return rb_funcall(rb_Float(x), '/', 1, y);
+ if (RB_TYPE_P(y, T_FLOAT)) {
+ return num_fdiv(x, y);
+ }
+
+ return rb_funcall(rb_rational_raw1(x), '/', 1, y);
}
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb
index a3cba398e31..9f709daa8a9 100644
--- a/test/ruby/test_bignum.rb
+++ b/test/ruby/test_bignum.rb
@@ -413,6 +413,8 @@ class TestBignum < Test::Unit::TestCase
end
def test_quo
+ assert_kind_of(Float, T32.quo(1.0))
+
assert_equal(T32.to_f, T32.quo(1))
assert_equal(T32.to_f, T32.quo(1.0))
assert_equal(T32.to_f, T32.quo(T_ONE))
@@ -420,7 +422,7 @@ class TestBignum < Test::Unit::TestCase
assert_raise(TypeError) { T32.quo("foo") }
assert_equal(1024**1024, (1024**1024).quo(1))
- assert_equal(1024**1024, (1024**1024).quo(1.0))
+ assert_equal(Float::INFINITY, (1024**1024).quo(1.0))
assert_equal(1024**1024*2, (1024**1024*2).quo(1))
inf = 1 / 0.0; nan = inf / inf
diff --git a/test/ruby/test_fixnum.rb b/test/ruby/test_fixnum.rb
index 85c8bdfa7b2..c016b2f4e02 100644
--- a/test/ruby/test_fixnum.rb
+++ b/test/ruby/test_fixnum.rb
@@ -157,6 +157,7 @@ class TestFixnum < Test::Unit::TestCase
assert_equal(0, 1 / (2**32))
assert_equal(0, 1.div(2**32))
+ assert_kind_of(Float, 1.quo(2.0))
assert_equal(0.5, 1.quo(2.0))
assert_equal(0.5, 1 / 2.0)
assert_equal(0, 1.div(2.0))