From 44a1d99635cde200a09e9d6c1667b7b9c1a327f2 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 18 Jun 2009 23:14:08 +0000 Subject: [PATCH] * bignum.c (big_lshift, big_rshift): return Bignum always without normalization. [ruby-dev:38679] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23739 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 ++++++- bignum.c | 42 +++++++++++++++++++++--------------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index a7e00cca44..eb15f745f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Jun 19 08:14:07 2009 Nobuyoshi Nakada + + * bignum.c (big_lshift, big_rshift): return Bignum always withou + normalization. [ruby-dev:38679] + Thu Jun 18 22:31:38 2009 Tadayoshi Funaba * rational.c (nurat_s_convert): calls to_r when the given argument @@ -124,7 +129,7 @@ Wed Jun 17 07:04:33 2009 Koichi Sasada Wed Jun 17 06:48:28 2009 Koichi Sasada * st.c, include/ruby/st.h (st_memsize): added. This function returns - the memory usage of st_talbe. + the memory usage of st_table. Wed Jun 17 06:19:06 2009 Koichi Sasada diff --git a/bignum.c b/bignum.c index bb6430c19d..d2f5ea3040 100644 --- a/bignum.c +++ b/bignum.c @@ -2412,23 +2412,23 @@ big_fdiv(VALUE x, VALUE y) case T_FIXNUM: y = rb_int2big(FIX2LONG(y)); case T_BIGNUM: { - bigtrunc(y); - l = RBIGNUM_LEN(y) - 1; - ey = l * BITSPERDIG; - ey += bdigbitsize(BDIGITS(y)[l]); - ey -= DBL_BIGDIG * BITSPERDIG; - if (ey) y = big_shift(y, ey); - bignum: - bigdivrem(x, y, &z, 0); - l = ex - ey; + bigtrunc(y); + l = RBIGNUM_LEN(y) - 1; + ey = l * BITSPERDIG; + ey += bdigbitsize(BDIGITS(y)[l]); + ey -= DBL_BIGDIG * BITSPERDIG; + if (ey) y = big_shift(y, ey); + bignum: + bigdivrem(x, y, &z, 0); + l = ex - ey; #if SIZEOF_LONG > SIZEOF_INT - { - /* Visual C++ can't be here */ - if (l > INT_MAX) return DBL2NUM(ruby_div0(1.0)); - if (l < INT_MIN) return DBL2NUM(0.0); - } + { + /* Visual C++ can't be here */ + if (l > INT_MAX) return DBL2NUM(ruby_div0(1.0)); + if (l < INT_MIN) return DBL2NUM(0.0); + } #endif - return DBL2NUM(ldexp(big2dbl(z), (int)l)); + return DBL2NUM(ldexp(big2dbl(z), (int)l)); } case T_FLOAT: y = dbl2big(ldexp(frexp(RFLOAT_VALUE(y), &i), DBL_MANT_DIG)); @@ -2896,8 +2896,8 @@ rb_big_lshift(VALUE x, VALUE y) y = rb_to_int(y); } - if (neg) return big_rshift(x, shift); - return big_lshift(x, shift); + x = neg ? big_rshift(x, shift) : big_lshift(x, shift); + return bignorm(x); } static VALUE @@ -2923,7 +2923,7 @@ big_lshift(VALUE x, unsigned long shift) num = BIGDN(num); } *zds = BIGLO(num); - return bignorm(z); + return z; } /* @@ -2962,8 +2962,8 @@ rb_big_rshift(VALUE x, VALUE y) y = rb_to_int(y); } - if (neg) return big_lshift(x, shift); - return big_rshift(x, shift); + x = neg ? big_lshift(x, shift) : big_rshift(x, shift); + return bignorm(x); } static VALUE @@ -3006,7 +3006,7 @@ big_rshift(VALUE x, unsigned long shift) if (!RBIGNUM_SIGN(x)) { get2comp(z); } - return bignorm(z); + return z; } /*