mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* bignum.c (Init_Bignum): rdiv method removed. [ruby-dev:34242]
* complex.c (nucomp_quo): ditto. * numeric.c (num_rdiv): ditto. * rational.c (nurat_div): ditto. * complex.c (nucomp_fdiv): fdiv implementation restored. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5d6602c44e
commit
228f30be3a
7 changed files with 27 additions and 89 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
Fri Apr 4 00:42:26 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* bignum.c (Init_Bignum): rdiv method removed. [ruby-dev:34242]
|
||||
|
||||
* complex.c (nucomp_quo): ditto.
|
||||
|
||||
* numeric.c (num_rdiv): ditto.
|
||||
|
||||
* rational.c (nurat_div): ditto.
|
||||
|
||||
* complex.c (nucomp_fdiv): fdiv implementation restored.
|
||||
|
||||
Thu Apr 3 21:51:45 2008 Tadayoshi Funaba <tadf@dotrb.org>
|
||||
|
||||
* complex.c (nucomp_int_check): function for DRY real check.
|
||||
|
|
1
bignum.c
1
bignum.c
|
@ -2650,7 +2650,6 @@ Init_Bignum(void)
|
|||
rb_define_method(rb_cBignum, "modulo", rb_big_modulo, 1);
|
||||
rb_define_method(rb_cBignum, "remainder", rb_big_remainder, 1);
|
||||
rb_define_method(rb_cBignum, "quo", rb_big_quo, 1);
|
||||
rb_define_method(rb_cBignum, "rdiv", rb_big_quo, 1);
|
||||
rb_define_method(rb_cBignum, "fdiv", rb_big_fdiv, 1);
|
||||
rb_define_method(rb_cBignum, "**", rb_big_pow, 1);
|
||||
rb_define_method(rb_cBignum, "&", rb_big_and, 1);
|
||||
|
|
|
@ -791,7 +791,7 @@ nucomp_div(VALUE self, VALUE other)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
nucomp_rdiv(VALUE self, VALUE other)
|
||||
nucomp_quo(VALUE self, VALUE other)
|
||||
{
|
||||
get_dat1(self);
|
||||
|
||||
|
@ -800,7 +800,6 @@ nucomp_rdiv(VALUE self, VALUE other)
|
|||
f_to_r(dat->image)), other);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static VALUE
|
||||
nucomp_fdiv(VALUE self, VALUE other)
|
||||
{
|
||||
|
@ -810,7 +809,6 @@ nucomp_fdiv(VALUE self, VALUE other)
|
|||
f_to_f(dat->real),
|
||||
f_to_f(dat->image)), other);
|
||||
}
|
||||
#endif
|
||||
|
||||
static VALUE
|
||||
nucomp_expt(VALUE self, VALUE other)
|
||||
|
@ -1550,9 +1548,8 @@ Init_Complex(void)
|
|||
rb_define_method(rb_cComplex, "-", nucomp_sub, 1);
|
||||
rb_define_method(rb_cComplex, "*", nucomp_mul, 1);
|
||||
rb_define_method(rb_cComplex, "/", nucomp_div, 1);
|
||||
rb_define_method(rb_cComplex, "quo", nucomp_rdiv, 1);
|
||||
rb_define_method(rb_cComplex, "rdiv", nucomp_rdiv, 1);
|
||||
rb_define_method(rb_cComplex, "fdiv", nucomp_rdiv, 1);
|
||||
rb_define_method(rb_cComplex, "quo", nucomp_quo, 1);
|
||||
rb_define_method(rb_cComplex, "fdiv", nucomp_fdiv, 1);
|
||||
rb_define_method(rb_cComplex, "**", nucomp_expt, 1);
|
||||
|
||||
rb_define_method(rb_cComplex, "==", nucomp_equal_p, 1);
|
||||
|
|
26
numeric.c
26
numeric.c
|
@ -266,27 +266,14 @@ num_fdiv(VALUE x, VALUE y)
|
|||
* num.quo(numeric) => result
|
||||
*
|
||||
* Suppose to return most accurate division result, which
|
||||
* by default in ratinal number for 1.9.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Document-method: rdiv
|
||||
*
|
||||
* call-seq:
|
||||
* num.rdiv(numeric) => result
|
||||
*
|
||||
* Performs rational number division.
|
||||
*
|
||||
* 654321.rdiv(13731) #=> Rational(218107, 4577)
|
||||
* 654321.rdiv(13731.5) #=> Rational(1308642, 27463)
|
||||
* is either rational or float (if any of operands are float).
|
||||
*
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
num_rdiv(VALUE x, VALUE y)
|
||||
num_quo(VALUE x, VALUE y)
|
||||
{
|
||||
return rb_funcall(rb_Rational1(x), rb_intern("rdiv"), 1, y);
|
||||
return rb_funcall(rb_Rational1(x), rb_intern("quo"), 1, y);
|
||||
}
|
||||
|
||||
static VALUE num_floor(VALUE num);
|
||||
|
@ -2248,8 +2235,8 @@ fixdivmod(long x, long y, long *divp, long *modp)
|
|||
* Returns the floating point result of dividing <i>fix</i> by
|
||||
* <i>numeric</i>.
|
||||
*
|
||||
* 654321.rdiv(13731) #=> Rational(218107, 4577)
|
||||
* 654321.rdiv(13731.24) #=> Rational(1308642, 27463)
|
||||
* 654321.quo(13731) #=> Rational(218107, 4577)
|
||||
* 654321.quo(13731.24) #=> xxx
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -3178,8 +3165,7 @@ Init_Numeric(void)
|
|||
rb_define_method(rb_cNumeric, "<=>", num_cmp, 1);
|
||||
rb_define_method(rb_cNumeric, "eql?", num_eql, 1);
|
||||
rb_define_method(rb_cNumeric, "fdiv", num_fdiv, 1);
|
||||
rb_define_method(rb_cNumeric, "quo", num_rdiv, 1);
|
||||
rb_define_method(rb_cNumeric, "rdiv", num_rdiv, 1);
|
||||
rb_define_method(rb_cNumeric, "quo", num_quo, 1);
|
||||
rb_define_method(rb_cNumeric, "div", num_div, 1);
|
||||
rb_define_method(rb_cNumeric, "divmod", num_divmod, 1);
|
||||
rb_define_method(rb_cNumeric, "modulo", num_modulo, 1);
|
||||
|
|
21
rational.c
21
rational.c
|
@ -781,7 +781,7 @@ nurat_mul(VALUE self, VALUE other)
|
|||
#define f_to_r(x) rb_funcall(x, id_to_r, 0)
|
||||
|
||||
static VALUE
|
||||
nurat_division(VALUE self, VALUE other, int rdiv)
|
||||
nurat_div(VALUE self, VALUE other)
|
||||
{
|
||||
again:
|
||||
switch (TYPE(other)) {
|
||||
|
@ -797,10 +797,6 @@ nurat_division(VALUE self, VALUE other, int rdiv)
|
|||
other, ONE, '/');
|
||||
}
|
||||
case T_FLOAT:
|
||||
if (rdiv) {
|
||||
other = f_to_r(other);
|
||||
goto again;
|
||||
}
|
||||
return rb_funcall(f_to_f(self), '/', 1, other);
|
||||
case T_RATIONAL:
|
||||
if (f_zero_p(other))
|
||||
|
@ -817,18 +813,6 @@ nurat_division(VALUE self, VALUE other, int rdiv)
|
|||
}
|
||||
}
|
||||
|
||||
static VALUE
|
||||
nurat_div(VALUE self, VALUE other)
|
||||
{
|
||||
return nurat_division(self, other, Qfalse);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
nurat_rdiv(VALUE self, VALUE other)
|
||||
{
|
||||
return nurat_division(self, other, Qtrue);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
nurat_fdiv(VALUE self, VALUE other)
|
||||
{
|
||||
|
@ -1549,8 +1533,7 @@ Init_Rational(void)
|
|||
rb_define_method(rb_cRational, "-", nurat_sub, 1);
|
||||
rb_define_method(rb_cRational, "*", nurat_mul, 1);
|
||||
rb_define_method(rb_cRational, "/", nurat_div, 1);
|
||||
rb_define_method(rb_cRational, "quo", nurat_rdiv, 1);
|
||||
rb_define_method(rb_cRational, "rdiv", nurat_rdiv, 1);
|
||||
rb_define_method(rb_cRational, "quo", nurat_div, 1);
|
||||
rb_define_method(rb_cRational, "fdiv", nurat_fdiv, 1);
|
||||
rb_define_method(rb_cRational, "**", nurat_expt, 1);
|
||||
|
||||
|
|
|
@ -413,30 +413,6 @@ class Complex_Test < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_rdiv
|
||||
if defined?(Rational) && !Rational.instance_variable_get('@RCS_ID')
|
||||
c = Complex(1,2)
|
||||
c2 = Complex(2,3)
|
||||
|
||||
assert_equal(Complex(Rational(8,13),Rational(1,13)), c.rdiv(c2))
|
||||
|
||||
c = Complex(1.0,2.0)
|
||||
c2 = Complex(2.0,3.0)
|
||||
|
||||
r = c.rdiv(c2)
|
||||
assert_in_delta(0.615, r.real, 0.001)
|
||||
assert_in_delta(0.076, r.image, 0.001)
|
||||
|
||||
c = Complex(1,2)
|
||||
c2 = Complex(2,3)
|
||||
|
||||
assert_equal(Complex(Rational(1,2),1), c.rdiv(2))
|
||||
|
||||
assert_equal(Complex(Rational(1,2),Rational(1)), c / Rational(2))
|
||||
assert_equal(Complex(Rational(3,2),Rational(3)), c / Rational(2,3))
|
||||
end
|
||||
end
|
||||
|
||||
def test_fdiv
|
||||
c = Complex(1,2)
|
||||
c2 = Complex(2,3)
|
||||
|
@ -880,10 +856,10 @@ class Complex_Test < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
if defined?(Rational) && !Rational.instance_variable_get('@RCS_ID')
|
||||
assert_equal(Rational(1,2), 1.rdiv(2))
|
||||
assert_equal(Rational(5000000000), 10000000000.rdiv(2))
|
||||
assert_equal(Rational(1,2), 1.0.rdiv(2))
|
||||
assert_equal(Rational(1,4), Rational(1,2).rdiv(2))
|
||||
assert_equal(Rational(1,2), 1.quo(2))
|
||||
assert_equal(Rational(5000000000), 10000000000.quo(2))
|
||||
assert_equal(Rational(1,2), 1.0.quo(2))
|
||||
assert_equal(Rational(1,4), Rational(1,2).quo(2))
|
||||
assert_equal(Complex(Rational(1,2),Rational(1)), Complex(1,2).quo(2))
|
||||
end
|
||||
|
||||
|
|
|
@ -502,16 +502,6 @@ class Rational_Test < Test::Unit::TestCase
|
|||
assert_equal(Rational(0.25), c.quo(2.0))
|
||||
end
|
||||
|
||||
def test_rdiv
|
||||
c = Rational(1,2)
|
||||
c2 = Rational(2,3)
|
||||
|
||||
assert_equal(Rational(3,4), c.rdiv(c2))
|
||||
|
||||
assert_equal(Rational(1,4), c.rdiv(2))
|
||||
assert_equal(Rational(0.25), c.rdiv(2.0))
|
||||
end
|
||||
|
||||
def test_fdiv
|
||||
c = Rational(1,2)
|
||||
c2 = Rational(2,3)
|
||||
|
@ -946,11 +936,6 @@ class Rational_Test < Test::Unit::TestCase
|
|||
assert_equal(Rational(1,2), 1.0.quo(2))
|
||||
assert_equal(Rational(1,4), Rational(1,2).quo(2))
|
||||
|
||||
assert_equal(Rational(1,2), 1.rdiv(2))
|
||||
assert_equal(Rational(5000000000), 10000000000.rdiv(2))
|
||||
assert_equal(Rational(1,2), 1.0.rdiv(2))
|
||||
assert_equal(Rational(1,4), Rational(1,2).rdiv(2))
|
||||
|
||||
assert_equal(0.5, 1.fdiv(2))
|
||||
assert_equal(5000000000.0, 10000000000.fdiv(2))
|
||||
assert_equal(0.5, 1.0.fdiv(2))
|
||||
|
|
Loading…
Reference in a new issue