summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-08-10 01:39:24 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-08-10 01:39:24 +0000
commit160055b47468d48dc0443bfbbeabf750bcfe8296 (patch)
tree49ff0eaefef57b5e29a37e7cb3515d77d8e9fae8 /bignum.c
parent5a0361f84c28d38747c066bda30ecf77483877f9 (diff)
* bignum.c (rb_big_mul0): multiply two numbers (x, y) without
normalizing the result. x should be a big number. [ruby-dev:26778] * bignum.c (rb_big_pow): use rb_big_mul0() instead of rb_big_mul(). * array.c (rb_ary_or, rb_ary_and, rb_ary_plus, rb_ary_diff): revert the change on 2005-08-03. Set operation on other item should have in separate methods. * parse.y (shadowing_lvar_gen): warn when arguments shadows external local variables. * parse.y (f_opt): optional arguments should not clobber external local variables. * parse.y (f_rest_arg): rest arguments should not clobber external local variables. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/bignum.c b/bignum.c
index 402de8a992..63ad2712bd 100644
--- a/bignum.c
+++ b/bignum.c
@@ -1214,15 +1214,8 @@ rb_big_minus(x, y)
}
}
-/*
- * call-seq:
- * big * other => Numeric
- *
- * Multiplies big and other, returning the result.
- */
-
-VALUE
-rb_big_mul(x, y)
+static VALUE
+rb_big_mul0(x, y)
VALUE x, y;
{
long i, j;
@@ -1230,7 +1223,6 @@ rb_big_mul(x, y)
VALUE z;
BDIGIT *zds;
- if (FIXNUM_P(x)) x = rb_int2big(FIX2LONG(x));
switch (TYPE(y)) {
case T_FIXNUM:
y = rb_int2big(FIX2LONG(y));
@@ -1264,8 +1256,21 @@ rb_big_mul(x, y)
zds[i + j] = n;
}
}
+ return z;
+}
- return bignorm(z);
+/*
+ * call-seq:
+ * big * other => Numeric
+ *
+ * Multiplies big and other, returning the result.
+ */
+
+VALUE
+rb_big_mul(x, y)
+ VALUE x, y;
+{
+ return bignorm(rb_big_mul0(x, y));
}
static void
@@ -1619,9 +1624,9 @@ rb_big_pow(x, y)
if (yy == 0) break;
while (yy % 2 == 0) {
yy /= 2;
- x = rb_big_mul(x, x);
+ x = rb_big_mul0(x, x);
}
- z = rb_big_mul(z, x);
+ z = rb_big_mul0(z, x);
}
return bignorm(z);
}
@@ -1979,6 +1984,9 @@ rb_big_coerce(x, y)
if (FIXNUM_P(y)) {
return rb_assoc_new(rb_int2big(FIX2LONG(y)), x);
}
+ else if (TYPE(y) == T_BIGNUM) {
+ return rb_assoc_new(y, x);
+ }
else {
rb_raise(rb_eTypeError, "can't coerce %s to Bignum",
rb_obj_classname(y));