mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
0b87f8d4cf
commit
5385ae9af4
4 changed files with 43 additions and 21 deletions
10
ChangeLog
10
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
|
||||
|
|
21
numeric.c
21
numeric.c
|
@ -383,26 +383,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
|
||||
|
@ -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);
|
||||
|
|
27
rational.c
27
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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue