ruby-changes:4841
From: ko1@a...
Date: Thu, 8 May 2008 18:19:02 +0900 (JST)
Subject: [ruby-changes:4841] matz - Ruby:r16335 (trunk): * bignum.c (rb_big_and): bit-wise operation should not take float
matz 2008-05-08 18:18:47 +0900 (Thu, 08 May 2008)
New Revision: 16335
Modified files:
trunk/ChangeLog
trunk/bignum.c
Log:
* bignum.c (rb_big_and): bit-wise operation should not take float
values. [ruby-dev:34612]
* bignum.c (rb_big_or): ditto.
* bignum.c (rb_big_xor): ditto.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16335&r2=16334&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/bignum.c?r1=16335&r2=16334&diff_format=u
Index: ChangeLog
===================================================================
--- ChangeLog (revision 16334)
+++ ChangeLog (revision 16335)
@@ -1,3 +1,12 @@
+Thu May 8 18:14:00 2008 Yukihiro Matsumoto <matz@r...>
+
+ * bignum.c (rb_big_and): bit-wise operation should not take float
+ values. [ruby-dev:34612]
+
+ * bignum.c (rb_big_or): ditto.
+
+ * bignum.c (rb_big_xor): ditto.
+
Thu May 8 17:44:13 2008 Nobuyoshi Nakada <nobu@r...>
* common.mk, ext/extmk.rb, lib/mkmf.rb: use absolute path for RUBYOPT.
Index: bignum.c
===================================================================
--- bignum.c (revision 16334)
+++ bignum.c (revision 16335)
@@ -2152,6 +2152,18 @@
return DOUBLE2NUM(pow(rb_big2dbl(x), d));
}
+static VALUE
+bit_coerce(VALUE x)
+{
+ while (!FIXNUM_P(x) && TYPE(x) != T_BIGNUM) {
+ if (TYPE(x) == T_FLOAT) {
+ rb_raise(rb_eTypeError, "can't convert Float into Integer");
+ }
+ x = rb_to_int(x);
+ }
+ return x;
+}
+
/*
* call-seq:
* big & numeric => integer
@@ -2168,7 +2180,7 @@
char sign;
x = xx;
- y = rb_to_int(yy);
+ y = bit_coerce(yy);
if (FIXNUM_P(y)) {
y = rb_int2big(FIX2LONG(y));
}
@@ -2223,7 +2235,7 @@
char sign;
x = xx;
- y = rb_to_int(yy);
+ y = bit_coerce(yy);
if (FIXNUM_P(y)) {
y = rb_int2big(FIX2LONG(y));
}
@@ -2281,7 +2293,7 @@
char sign;
x = xx;
- y = rb_to_int(yy);
+ y = bit_coerce(yy);
if (FIXNUM_P(y)) {
y = rb_int2big(FIX2LONG(y));
}
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/