[前][次][番号順一覧][スレッド一覧]

ruby-changes:29047

From: mrkn <ko1@a...>
Date: Thu, 6 Jun 2013 10:04:24 +0900 (JST)
Subject: [ruby-changes:29047] mrkn:r41099 (trunk): * numeric.c (num_quo): should return a Float for a Float argument.

mrkn	2013-06-06 10:04:11 +0900 (Thu, 06 Jun 2013)

  New Revision: 41099

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41099

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/numeric.c
    trunk/test/ruby/test_bignum.rb
    trunk/test/ruby/test_fixnum.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41098)
+++ ChangeLog	(revision 41099)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jun  6 09:41:00 2013  Kenta Murata  <mrkn@c...>
+
+	* 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@r...>
 
 	* gc.c (gc_mark): get rid of pushing useless objests.
Index: numeric.c
===================================================================
--- numeric.c	(revision 41098)
+++ numeric.c	(revision 41099)
@@ -371,29 +371,34 @@ num_uminus(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L371
 
 /*
  *  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);
 }
 
 
Index: test/ruby/test_bignum.rb
===================================================================
--- test/ruby/test_bignum.rb	(revision 41098)
+++ test/ruby/test_bignum.rb	(revision 41099)
@@ -413,6 +413,8 @@ class TestBignum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_bignum.rb#L413
   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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_bignum.rb#L422
     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
 
Index: test/ruby/test_fixnum.rb
===================================================================
--- test/ruby/test_fixnum.rb	(revision 41098)
+++ test/ruby/test_fixnum.rb	(revision 41099)
@@ -157,6 +157,7 @@ class TestFixnum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_fixnum.rb#L157
     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))

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]