summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-08 09:18:47 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-08 09:18:47 +0000
commit1b487a39d6eec783b5b39f8d9d18874805592e0b (patch)
treee73e20bfbe0db0d7dfe3e8fe662fab41d5fc785f
parenta19df6ab201992c552ed920e2cdaeeeb737063ac (diff)
downloadruby-1b487a39d6eec783b5b39f8d9d18874805592e0b.tar.gz
ruby-1b487a39d6eec783b5b39f8d9d18874805592e0b.tar.xz
ruby-1b487a39d6eec783b5b39f8d9d18874805592e0b.zip
* 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. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--bignum.c18
2 files changed, 24 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 7350e4fac..944b48cb5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Thu May 8 18:14:00 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* common.mk, ext/extmk.rb, lib/mkmf.rb: use absolute path for RUBYOPT.
diff --git a/bignum.c b/bignum.c
index b95e51eb6..536094f23 100644
--- a/bignum.c
+++ b/bignum.c
@@ -2152,6 +2152,18 @@ rb_big_pow(VALUE x, VALUE y)
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 @@ rb_big_and(VALUE xx, VALUE yy)
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 @@ rb_big_or(VALUE xx, VALUE yy)
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 @@ rb_big_xor(VALUE xx, VALUE yy)
char sign;
x = xx;
- y = rb_to_int(yy);
+ y = bit_coerce(yy);
if (FIXNUM_P(y)) {
y = rb_int2big(FIX2LONG(y));
}