summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-26 19:21:02 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-06-26 19:21:02 +0000
commit49dbacf73ee33ea17204b2bd47a13c1b223cf4d6 (patch)
tree87cf935675029f86837f06ea74e178f873b14dd8 /bignum.c
parent0659c5351e05e9f19939c1f6a229ca494a61597e (diff)
merge revision(s) 35081: [Backport #6605]
* bignum.c (rb_big_pow): estimate result bit size more precisely. [ruby-core:30735][Feature #3429] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@36226 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/bignum.c b/bignum.c
index 9c289f7a8e..8d024fe5cc 100644
--- a/bignum.c
+++ b/bignum.c
@@ -3079,10 +3079,11 @@ rb_big_pow(VALUE x, VALUE y)
else {
VALUE z = 0;
SIGNED_VALUE mask;
- const long BIGLEN_LIMIT = 1024*1024 / SIZEOF_BDIGITS;
+ const long xlen = RBIGNUM_LEN(x) - 1;
+ const long xbits = ffs(RBIGNUM_DIGITS(x)[xlen]) + SIZEOF_BDIGITS*BITSPERDIG*xlen;
+ const long BIGLEN_LIMIT = BITSPERDIG*1024*1024;
- if ((RBIGNUM_LEN(x) > BIGLEN_LIMIT) ||
- (RBIGNUM_LEN(x) > BIGLEN_LIMIT / yy)) {
+ if ((xbits > BIGLEN_LIMIT) || (xbits * yy > BIGLEN_LIMIT)) {
rb_warn("in a**b, b may be too big");
d = (double)yy;
break;