diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-06-26 19:21:02 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-06-26 19:21:02 +0000 |
commit | 49dbacf73ee33ea17204b2bd47a13c1b223cf4d6 (patch) | |
tree | 87cf935675029f86837f06ea74e178f873b14dd8 /bignum.c | |
parent | 0659c5351e05e9f19939c1f6a229ca494a61597e (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.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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; |