summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-07 02:50:32 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-07 02:50:32 +0000
commit5385ae9af43208c014040ed1025b09415d48b36f (patch)
tree099bef333ef1a2c93c01e5a07486b287d36e3962
parent0b87f8d4cfa627173037c00712e28eb0d5df8307 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41132 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog10
-rw-r--r--numeric.c21
-rw-r--r--rational.c27
-rw-r--r--test/test_mathn.rb6
4 files changed, 43 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 1c7f93143c..702bc23289 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Fri Jun 7 11:45:42 2013 Kenta Murata <mrkn@cookpad.com>
+
+ * 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@ruby-lang.org>
* configure.in: revert r41106. size_t may not be unsigned
diff --git a/numeric.c b/numeric.c
index 00f290cc97..f675034e6c 100644
--- a/numeric.c
+++ b/numeric.c
@@ -385,26 +385,6 @@ num_fdiv(VALUE x, VALUE y)
/*
* 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)
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);
diff --git a/rational.c b/rational.c
index d5942f1add..86c33b539c 100644
--- a/rational.c
+++ b/rational.c
@@ -1793,6 +1793,32 @@ numeric_denominator(VALUE self)
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)
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);
diff --git a/test/test_mathn.rb b/test/test_mathn.rb
index 7f2b294bba..135f66f261 100644
--- a/test/test_mathn.rb
+++ b/test/test_mathn.rb
@@ -9,4 +9,10 @@ class TestMathn < Test::Unit::TestCase
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