summaryrefslogtreecommitdiff
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
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
-rw-r--r--ChangeLog5
-rw-r--r--bignum.c7
-rw-r--r--test/ruby/test_bignum.rb3
-rw-r--r--version.h6
4 files changed, 15 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index ca9dce7216..eb72ea898c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Jun 27 04:20:41 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * bignum.c (rb_big_pow): estimate result bit size more precisely.
+ [ruby-core:30735][Feature #3429]
+
Tue Jun 26 20:36:53 2012 Tanaka Akira <akr@fsij.org>
* lib/drb/ssl.rb: generate 1024 bits RSA key instead of 512 bits.
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;
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb
index 264c68bcf7..062d8cb4bf 100644
--- a/test/ruby/test_bignum.rb
+++ b/test/ruby/test_bignum.rb
@@ -299,6 +299,9 @@ class TestBignum < Test::Unit::TestCase
### 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
diff --git a/version.h b/version.h
index da2cac4899..68ad486f2b 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@
#define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 239
+#define RUBY_PATCHLEVEL 240
-#define RUBY_RELEASE_DATE "2012-06-26"
+#define RUBY_RELEASE_DATE "2012-06-27"
#define RUBY_RELEASE_YEAR 2012
#define RUBY_RELEASE_MONTH 6
-#define RUBY_RELEASE_DAY 26
+#define RUBY_RELEASE_DAY 27
#include "ruby/version.h"