mirror of
https://github.com/ruby/ruby.git
synced 2025-09-19 18:43:59 +02:00
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
This commit is contained in:
parent
0659c5351e
commit
49dbacf73e
4 changed files with 15 additions and 6 deletions
7
bignum.c
7
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue