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

ruby-changes:29080

From: mrkn <ko1@a...>
Date: Fri, 7 Jun 2013 11:50:44 +0900 (JST)
Subject: [ruby-changes:29080] mrkn:r41132 (trunk): * rational.c (numeric_quo): move num_quo in numeric.c to numeric_quo

mrkn	2013-06-07 11:50:32 +0900 (Fri, 07 Jun 2013)

  New Revision: 41132

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

  Log:
    * rational.c (numeric_quo): move num_quo in numeric.c to numeric_quo
      in rational.c to refer canonicalization state for mathn support.
      [ruby-core:41575] [Bug #5736]
    
    * numeric.c (num_quo): ditto.
    
    * test/test_mathn.rb: add a test for the change at r41109.

  Modified files:
    trunk/ChangeLog
    trunk/numeric.c
    trunk/rational.c
    trunk/test/test_mathn.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41131)
+++ ChangeLog	(revision 41132)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jun  7 11:45:42 2013  Kenta Murata  <mrkn@c...>
+
+	* rational.c (numeric_quo): move num_quo in numeric.c to numeric_quo
+	  in rational.c to refer canonicalization state for mathn support.
+	  [ruby-core:41575] [Bug #5736]
+
+	* numeric.c (num_quo): ditto.
+
+	* test/test_mathn.rb: add a test for the change at r41109.
+
 Fri Jun  7 11:41:42 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in: revert r41106.  size_t may not be unsigned
Index: numeric.c
===================================================================
--- numeric.c	(revision 41131)
+++ numeric.c	(revision 41132)
@@ -385,26 +385,6 @@ num_fdiv(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L385
 
 /*
  *  call-seq:
- *     num.quo(int_or_rat)   ->  rat
- *     num.quo(flo)          ->  flo
- *
- *  Returns most exact division (rational for integers, float for floats).
- */
-
-static VALUE
-num_quo(VALUE x, VALUE y)
-{
-    if (RB_TYPE_P(y, T_FLOAT)) {
-        return num_fdiv(x, y);
-    }
-
-    x = rb_convert_type(x, T_RATIONAL, "Rational", "to_r");
-    return rb_funcall(x, '/', 1, y);
-}
-
-
-/*
- *  call-seq:
  *     num.div(numeric)  ->  integer
  *
  *  Uses <code>/</code> to perform division, then converts the result to
@@ -3792,7 +3772,6 @@ Init_Numeric(void) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3772
     rb_define_method(rb_cNumeric, "-@", num_uminus, 0);
     rb_define_method(rb_cNumeric, "<=>", num_cmp, 1);
     rb_define_method(rb_cNumeric, "eql?", num_eql, 1);
-    rb_define_method(rb_cNumeric, "quo", num_quo, 1);
     rb_define_method(rb_cNumeric, "fdiv", num_fdiv, 1);
     rb_define_method(rb_cNumeric, "div", num_div, 1);
     rb_define_method(rb_cNumeric, "divmod", num_divmod, 1);
Index: test/test_mathn.rb
===================================================================
--- test/test_mathn.rb	(revision 41131)
+++ test/test_mathn.rb	(revision 41132)
@@ -9,4 +9,10 @@ class TestMathn < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_mathn.rb#L9
     assert_in_out_err ['-r', 'mathn/complex', '-e', 'a=Complex(0,1)**4;!a'], "", [], [], '[ruby-core:44170]'
     assert_in_out_err ['-r', 'mathn/complex', '-e', 'a=Complex(0,1)**5;!a'], "", [], [], '[ruby-core:44170]'
   end
+
+  def test_quo
+    assert_in_out_err ['-r', 'mathn'], <<-EOS, %w(OK), [], '[ruby-core:41575]'
+      1.quo(2); puts :OK
+    EOS
+  end
 end
Index: rational.c
===================================================================
--- rational.c	(revision 41131)
+++ rational.c	(revision 41132)
@@ -1793,6 +1793,32 @@ numeric_denominator(VALUE self) https://github.com/ruby/ruby/blob/trunk/rational.c#L1793
     return f_denominator(f_to_r(self));
 }
 
+
+/*
+ *  call-seq:
+ *     num.quo(int_or_rat)   ->  rat
+ *     num.quo(flo)          ->  flo
+ *
+ *  Returns most exact division (rational for integers, float for floats).
+ */
+
+static VALUE
+numeric_quo(VALUE x, VALUE y)
+{
+    if (RB_TYPE_P(y, T_FLOAT)) {
+        return f_fdiv(x, y);
+    }
+
+    if (canonicalization) {
+        x = rb_rational_raw1(x);
+    }
+    else {
+        x = rb_convert_type(x, T_RATIONAL, "Rational", "to_r");
+    }
+    return rb_funcall(x, '/', 1, y);
+}
+
+
 /*
  * call-seq:
  *    int.numerator  ->  self
@@ -2529,6 +2555,7 @@ Init_Rational(void) https://github.com/ruby/ruby/blob/trunk/rational.c#L2555
 
     rb_define_method(rb_cNumeric, "numerator", numeric_numerator, 0);
     rb_define_method(rb_cNumeric, "denominator", numeric_denominator, 0);
+    rb_define_method(rb_cNumeric, "quo", numeric_quo, 1);
 
     rb_define_method(rb_cInteger, "numerator", integer_numerator, 0);
     rb_define_method(rb_cInteger, "denominator", integer_denominator, 0);

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

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