mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* numeric.c (bit_coerce): float should not be a valid operand of
bitwise operations. [ruby-dev:34583] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16316 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
98ad274974
commit
10f263c10e
3 changed files with 17 additions and 8 deletions
|
@ -4,6 +4,11 @@ Wed May 7 20:19:18 2008 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
after Init_prelude() because cannot load encoding extensions before
|
after Init_prelude() because cannot load encoding extensions before
|
||||||
it.
|
it.
|
||||||
|
|
||||||
|
Wed May 7 20:00:21 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* numeric.c (bit_coerce): float should not be a valid operand of
|
||||||
|
bitwise operations. [ruby-dev:34583]
|
||||||
|
|
||||||
Wed May 7 19:35:29 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Wed May 7 19:35:29 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* thread.c (rb_thread_key_p): should always convert symbol to ID.
|
* thread.c (rb_thread_key_p): should always convert symbol to ID.
|
||||||
|
|
14
numeric.c
14
numeric.c
|
@ -2636,9 +2636,12 @@ fix_rev(VALUE num)
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
fix_coerce(VALUE x)
|
bit_coerce(VALUE x)
|
||||||
{
|
{
|
||||||
while (!FIXNUM_P(x) && TYPE(x) != T_BIGNUM) {
|
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);
|
x = rb_to_int(x);
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
|
@ -2656,7 +2659,7 @@ fix_and(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
long val;
|
long val;
|
||||||
|
|
||||||
if (!FIXNUM_P(y = fix_coerce(y))) {
|
if (!FIXNUM_P(y = bit_coerce(y))) {
|
||||||
return rb_big_and(y, x);
|
return rb_big_and(y, x);
|
||||||
}
|
}
|
||||||
val = FIX2LONG(x) & FIX2LONG(y);
|
val = FIX2LONG(x) & FIX2LONG(y);
|
||||||
|
@ -2675,7 +2678,7 @@ fix_or(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
long val;
|
long val;
|
||||||
|
|
||||||
if (!FIXNUM_P(y = fix_coerce(y))) {
|
if (!FIXNUM_P(y = bit_coerce(y))) {
|
||||||
return rb_big_or(y, x);
|
return rb_big_or(y, x);
|
||||||
}
|
}
|
||||||
val = FIX2LONG(x) | FIX2LONG(y);
|
val = FIX2LONG(x) | FIX2LONG(y);
|
||||||
|
@ -2694,7 +2697,7 @@ fix_xor(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
long val;
|
long val;
|
||||||
|
|
||||||
if (!FIXNUM_P(y = fix_coerce(y))) {
|
if (!FIXNUM_P(y = bit_coerce(y))) {
|
||||||
return rb_big_xor(y, x);
|
return rb_big_xor(y, x);
|
||||||
}
|
}
|
||||||
val = FIX2LONG(x) ^ FIX2LONG(y);
|
val = FIX2LONG(x) ^ FIX2LONG(y);
|
||||||
|
@ -2791,7 +2794,8 @@ fix_aref(VALUE fix, VALUE idx)
|
||||||
long val = FIX2LONG(fix);
|
long val = FIX2LONG(fix);
|
||||||
long i;
|
long i;
|
||||||
|
|
||||||
if (!FIXNUM_P(idx = fix_coerce(idx))) {
|
idx = rb_to_int(idx);
|
||||||
|
if (!FIXNUM_P(idx)) {
|
||||||
idx = rb_big_norm(idx);
|
idx = rb_big_norm(idx);
|
||||||
if (!FIXNUM_P(idx)) {
|
if (!FIXNUM_P(idx)) {
|
||||||
if (!RBIGNUM_SIGN(idx) || val >= 0)
|
if (!RBIGNUM_SIGN(idx) || val >= 0)
|
||||||
|
|
|
@ -201,9 +201,9 @@ class TestNumeric < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_num2long
|
def test_num2long
|
||||||
assert_raise(TypeError) { 1 & nil }
|
assert_raise(TypeError) { 1 & nil }
|
||||||
assert_equal(1, 1 & 1.0)
|
assert_raise(TypeError) { 1 & 1.0 }
|
||||||
assert_equal(0, 1 & 2147483648.0)
|
assert_raise(TypeError) { 1 & 2147483648.0 }
|
||||||
assert_equal(0, 1 & 9223372036854777856.0)
|
assert_raise(TypeError) { 1 & 9223372036854777856.0 }
|
||||||
o = Object.new
|
o = Object.new
|
||||||
def o.to_int; 1; end
|
def o.to_int; 1; end
|
||||||
assert_equal(1, 1 & o)
|
assert_equal(1, 1 & o)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue