summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-10-05 16:15:16 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-10-05 16:15:16 +0000
commit22f1926644a213a39cd8a3f83a80518e5c15797f (patch)
tree664beb18420f4bc9329dc37e52bdeafbf000037a /numeric.c
parent313e0cb56aedfceb0bfaab2e430d2211c5e2043b (diff)
* range.c (rb_range_beg_len): should return Qfalse for non-range
object. * pack.c (EXTEND16): [ruby-dev:27383] * eval.c (set_trace_func): add rb_secure(4) to prevent adding tracing function. * lib/delegate.rb: document update from James Edward Gray II <james@grayproductions.net>. [ruby-core:05942] * process.c (proc_daemon): should restrict execution on levels higher than $SAFE=2. suggested by URABE Shyouhei <shyouhei@ice.uec.ac.jp>. * lib/forwardable.rb: replaced by new implementation from <Daniel.Berger@qwest.com>. [ruby-core:05899] * file.c (path_check_0): disallow sticky world writable directory in PATH (and $LOAD_PATH). [ruby-dev:27226] * numeric.c (fix_idiv): 1.div(1.0) should return integer value. [ruby-dev:27235] * lib/yaml.rb: require 'yaml/constants'. [ruby-core:5776] * lib/xmlrpc/client.rb (XMLRPC::Client::do_rpc): add charset information to content-type header.[ruby-core:5127] * lib/xmlrpc/server.rb (CGIServer::serve): ditto. * lib/xmlrpc/server.rb (ModRubyServer::serve): ditto. * lib/xmlrpc/server.rb (WEBrickServlet::service): ditto. * test/dbm/test_dbm.rb (TestDBM::test_s_open_error): remove test_s_open_error test to detect duplicate open. [ruby-dev:27202] * eval.c (splat_value): use to_a to splat non Array object. * object.c (nil_to_a): remove nil.to_a. [experimental] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9349 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/numeric.c b/numeric.c
index 8ab8cd6623..3c8adac113 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2039,18 +2039,8 @@ fix_quo(VALUE x, VALUE y)
}
}
-/*
- * call-seq:
- * fix / numeric => numeric_result
- * fix.div(numeric) => numeric_result
- *
- * Performs division: the class of the resulting object depends on
- * the class of <code>numeric</code> and on the magnitude of the
- * result.
- */
-
static VALUE
-fix_div(VALUE x, VALUE y)
+fix_divide(VALUE x, VALUE y, int flo)
{
if (FIXNUM_P(y)) {
long div;
@@ -2063,13 +2053,47 @@ fix_div(VALUE x, VALUE y)
x = rb_int2big(FIX2LONG(x));
return rb_big_div(x, y);
case T_FLOAT:
- return rb_float_new((double)FIX2LONG(x) / RFLOAT(y)->value);
+ if (flo) {
+ return rb_float_new((double)FIX2LONG(x) / RFLOAT(y)->value);
+ }
+ else {
+ long div = (double)FIX2LONG(x) / RFLOAT(y)->value;
+ return LONG2NUM(div);
+ }
default:
return rb_num_coerce_bin(x, y);
}
}
/*
+ * call-seq:
+ * fix / numeric => numeric_result
+ *
+ * Performs division: the class of the resulting object depends on
+ * the class of <code>numeric</code> and on the magnitude of the
+ * result.
+ */
+
+static VALUE
+fix_div(VALUE x, VALUE y)
+{
+ return fix_divide(x, y, Qtrue);
+}
+
+/*
+ * call-seq:
+ * fix.div(numeric) => numeric_result
+ *
+ * Performs integer division: returns integer value.
+ */
+
+static VALUE
+fix_idiv(VALUE x, VALUE y)
+{
+ return fix_divide(x, y, Qfalse);
+}
+
+/*
* call-seq:
* fix % other => Numeric
* fix.modulo(other) => Numeric
@@ -2824,7 +2848,7 @@ Init_Numeric(void)
rb_define_method(rb_cFixnum, "-", fix_minus, 1);
rb_define_method(rb_cFixnum, "*", fix_mul, 1);
rb_define_method(rb_cFixnum, "/", fix_div, 1);
- rb_define_method(rb_cFixnum, "div", fix_div, 1);
+ rb_define_method(rb_cFixnum, "div", fix_idiv, 1);
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);