From 35b21a12c03765244d32b6400a100124f35df091 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 29 Oct 2001 05:04:45 +0000 Subject: * parse.y (str_extend): shuould allow interpolation of $-x. * bignum.c (rb_big_eq): convert Bignum to Float, instead of reverse. * time.c (time_localtime): getting tm should not be prohibited for frozen time objects. * time.c (time_gmtime): ditto. * version.c (Init_version): freeze RUBY_VERSION, RUBY_RELEASE_DATE, and RUBY_PLATFORM. * file.c (Init_File): freeze File::SEPARATOR, ALT_SEPARATOR and PATH_SEPARATOR. * file.c (rb_stat_cmp): should check operand type before calling get_stat(). * eval.c (rb_eval_cmd): should not invoke "call" with a block on any occasion. * numeric.c (fix_aref): idx may be a Bignum. * numeric.c (num_remainder): a bug in Numeric#remainder. * eval.c (rb_exec_end_proc): END might be called within END block. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1799 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index 675528475f..33ec3605e6 100644 --- a/numeric.c +++ b/numeric.c @@ -146,10 +146,11 @@ num_remainder(x, y) { VALUE z = rb_funcall(x, '%', 1, y); - if ((RTEST(rb_funcall(x, '<', 1, INT2FIX(0))) && - RTEST(rb_funcall(y, '>', 1, INT2FIX(0)))) || - (RTEST(rb_funcall(x, '>', 1, INT2FIX(0))) && - RTEST(rb_funcall(y, '<', 1, INT2FIX(0))))) { + if ((!RTEST(rb_equal(z, INT2FIX(0)))) && + ((RTEST(rb_funcall(x, '<', 1, INT2FIX(0))) && + RTEST(rb_funcall(y, '>', 1, INT2FIX(0)))) || + (RTEST(rb_funcall(x, '>', 1, INT2FIX(0))) && + RTEST(rb_funcall(y, '<', 1, INT2FIX(0)))))) { return rb_funcall(z, '-', 1, y); } return z; @@ -1302,15 +1303,22 @@ fix_aref(fix, idx) VALUE fix, idx; { long val = FIX2LONG(fix); - int i = NUM2INT(idx); - if (i < 0 || sizeof(VALUE)*CHAR_BIT-1 < i) { - if (val < 0) return INT2FIX(1); + if (TYPE(idx) == T_BIGNUM) { + if (val >= 0) return INT2FIX(0); + return INT2FIX(1); + } + else { + int i = NUM2INT(idx); + + if (i < 0 || sizeof(VALUE)*CHAR_BIT-1 < i) { + if (val < 0) return INT2FIX(1); + return INT2FIX(0); + } + if (val & (1L<