ruby-changes:23032
From: nobu <ko1@a...>
Date: Sun, 18 Mar 2012 17:18:05 +0900 (JST)
Subject: [ruby-changes:23032] nobu:r35081 (trunk): * bignum.c (rb_big_pow): estimate result bit size more precisely.
nobu 2012-03-18 17:17:50 +0900 (Sun, 18 Mar 2012) New Revision: 35081 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35081 Log: * bignum.c (rb_big_pow): estimate result bit size more precisely. [ruby-core:30735][Feature #3429] Modified files: trunk/ChangeLog trunk/bignum.c trunk/test/ruby/test_bignum.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 35080) +++ ChangeLog (revision 35081) @@ -1,3 +1,8 @@ +Sun Mar 18 17:17:48 2012 Nobuyoshi Nakada <nobu@r...> + + * bignum.c (rb_big_pow): estimate result bit size more precisely. + [ruby-core:30735][Feature #3429] + Sun Mar 18 17:17:36 2012 Nobuyoshi Nakada <nobu@r...> * gc.c (free_method_entry_i): method entry may be in Index: bignum.c =================================================================== --- bignum.c (revision 35080) +++ bignum.c (revision 35081) @@ -3095,10 +3095,11 @@ 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; Index: test/ruby/test_bignum.rb =================================================================== --- test/ruby/test_bignum.rb (revision 35080) +++ test/ruby/test_bignum.rb (revision 35081) @@ -326,6 +326,9 @@ ### rational changes the behavior of Bignum#** #assert_raise(TypeError) { T32**"foo" } assert_raise(TypeError, ArgumentError) { T32**"foo" } + + feature3429 = '[ruby-core:30735]' + assert_instance_of(Bignum, (2 ** 7830457), feature3429) end def test_and -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/