From 5f61a22950233184db0771ef743706f7c3f99371 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 4 Sep 2006 20:10:45 +0000 Subject: * numeric.c (fix_plus): addition in Fixnum will never overflow long. a patch from Ondrej Bilka . [ruby-core:08794] * numeric.c (fix_minus): ditto. * bignum.c (rb_big_pow): eagerly truncate resulting bignum. [ruby-core:08794] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ bignum.c | 2 ++ numeric.c | 10 ++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index cf48c224a3..6d2df6929d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Tue Sep 5 05:03:46 2006 Yukihiro Matsumoto + + * numeric.c (fix_plus): addition in Fixnum will never overflow + long. a patch from Ondrej Bilka . + [ruby-core:08794] + + * numeric.c (fix_minus): ditto. + + * bignum.c (rb_big_pow): eagerly truncate resulting bignum. + [ruby-core:08794] + Mon Sep 4 23:15:34 2006 Yukihiro Matsumoto * time.c (time_to_s): make it conform to RFC2822 date format. diff --git a/bignum.c b/bignum.c index dd29124995..e3e8d80d9a 100644 --- a/bignum.c +++ b/bignum.c @@ -1553,8 +1553,10 @@ rb_big_pow(VALUE x, VALUE y) while (yy % 2 == 0) { yy /= 2; x = rb_big_mul0(x, x); + if (!BDIGITS(x)[RBIGNUM(x)->len-1]) RBIGNUM(x)->len--; } z = rb_big_mul0(z, x); + if (!BDIGITS(z)[RBIGNUM(z)->len-1]) RBIGNUM(z)->len--; } return bignorm(z); } diff --git a/numeric.c b/numeric.c index 5a08f0637b..d5829d14a3 100644 --- a/numeric.c +++ b/numeric.c @@ -1908,11 +1908,8 @@ fix_plus(VALUE x, VALUE y) a = FIX2LONG(x); b = FIX2LONG(y); c = a + b; - r = LONG2FIX(c); + r = LONG2NUM(c); - if (FIX2LONG(r) != c) { - r = rb_big_plus(rb_int2big(a), rb_int2big(b)); - } return r; } switch (TYPE(y)) { @@ -1944,11 +1941,8 @@ fix_minus(VALUE x, VALUE y) a = FIX2LONG(x); b = FIX2LONG(y); c = a - b; - r = LONG2FIX(c); + r = LONG2NUM(c); - if (FIX2LONG(r) != c) { - r = rb_big_minus(rb_int2big(a), rb_int2big(b)); - } return r; } switch (TYPE(y)) { -- cgit v1.2.3