From 79ed2cc1af8cfb75fba2109e91f70abe4fa83370 Mon Sep 17 00:00:00 2001 From: tadf Date: Mon, 7 Apr 2008 13:52:26 +0000 Subject: * numeric.c: cancelled recent changes (except to remove rdiv). * bignum.c: ditto. * bignum.c: added rb_big_idiv. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15918 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index 4730e6278..67ef22ac9 100644 --- a/numeric.c +++ b/numeric.c @@ -247,39 +247,20 @@ num_uminus(VALUE num) } /* - * call-seq: - * num.fdiv(numeric) => result - * - * Performs floating point division. - */ - -static VALUE -num_fdiv(VALUE x, VALUE y) -{ - return rb_funcall(rb_Float(x), '/', 1, y); -} - -/* - * Document-method: quo - * * call-seq: * num.quo(numeric) => result + * num.fdiv(numeric) => result * - * Suppose to return most accurate division result, which - * is either rational or float (if any of operands are float). - * - * - * 654321.quo(13731) #=> Rational(218107, 4577) - * 654321.quo(13731.24) #=> 47.6519964693647 - * + * Equivalent to Numeric#/, but overridden in subclasses. */ static VALUE num_quo(VALUE x, VALUE y) { - return rb_funcall(rb_Rational1(x), rb_intern("quo"), 1, y); + return rb_funcall(x, '/', 1, y); } + static VALUE num_floor(VALUE num); /* @@ -294,7 +275,7 @@ static VALUE num_floor(VALUE num); static VALUE num_div(VALUE x, VALUE y) { - return rb_funcall(rb_funcall(x, '/', 1, y), rb_intern("floor"), 0, 0); + return num_floor(rb_funcall(x, '/', 1, y)); } @@ -666,7 +647,7 @@ flo_div(VALUE x, VALUE y) } static VALUE -flo_fdiv(VALUE x, VALUE y) +flo_quo(VALUE x, VALUE y) { return rb_funcall(x, '/', 1, y); } @@ -2234,12 +2215,23 @@ fixdivmod(long x, long y, long *divp, long *modp) /* * call-seq: - * fix.fdiv(numeric) => float + * fix.quo(numeric) => float + * fix.fdiv(numeric) => float * * Returns the floating point result of dividing fix by * numeric. + * + * 654321.quo(13731) #=> 47.6528293642124 + * 654321.quo(13731.24) #=> 47.6519964693647 + * */ +static VALUE +fix_quo(VALUE x, VALUE y) +{ + return rb_funcall(rb_rational_raw1(x), '/', 1, y); +} + static VALUE fix_fdiv(VALUE x, VALUE y) { @@ -3164,8 +3156,8 @@ 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, "fdiv", num_fdiv, 1); rb_define_method(rb_cNumeric, "quo", num_quo, 1); + rb_define_method(rb_cNumeric, "fdiv", 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); @@ -3231,6 +3223,7 @@ Init_Numeric(void) rb_define_method(rb_cFixnum, "%", fix_mod, 1); rb_define_method(rb_cFixnum, "modulo", fix_mod, 1); rb_define_method(rb_cFixnum, "divmod", fix_divmod, 1); + rb_define_method(rb_cFixnum, "quo", fix_quo, 1); rb_define_method(rb_cFixnum, "fdiv", fix_fdiv, 1); rb_define_method(rb_cFixnum, "**", fix_pow, 1); @@ -3286,7 +3279,8 @@ Init_Numeric(void) rb_define_method(rb_cFloat, "-", flo_minus, 1); rb_define_method(rb_cFloat, "*", flo_mul, 1); rb_define_method(rb_cFloat, "/", flo_div, 1); - rb_define_method(rb_cFloat, "fdiv", flo_fdiv, 1); + rb_define_method(rb_cFloat, "quo", flo_quo, 1); + rb_define_method(rb_cFloat, "fdiv", flo_quo, 1); rb_define_method(rb_cFloat, "%", flo_mod, 1); rb_define_method(rb_cFloat, "modulo", flo_mod, 1); rb_define_method(rb_cFloat, "divmod", flo_divmod, 1); -- cgit