aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bignum.c3
-rw-r--r--test/ruby/test_integer.rb12
2 files changed, 15 insertions, 0 deletions
diff --git a/bignum.c b/bignum.c
index d1e83565c9..3207af9616 100644
--- a/bignum.c
+++ b/bignum.c
@@ -6824,6 +6824,9 @@ estimate_initial_sqrt(VALUE *xp, const size_t xn, const BDIGIT *nds, size_t len)
if (lowbits || (lowbits = !bary_zero_p(nds, len-dbl_per_bdig)))
++d;
}
+ else {
+ lowbits = 1;
+ }
rshift /= 2;
rshift += (2-(len&1))*BITSPERDIG/2;
if (rshift >= 0) {
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb
index e0927c9ffe..963c6b75a4 100644
--- a/test/ruby/test_integer.rb
+++ b/test/ruby/test_integer.rb
@@ -488,5 +488,17 @@ class TestInteger < Test::Unit::TestCase
assert_equal(exact, Integer.sqrt(x+1), "10**#{i}+1")
assert_equal(exact-1, Integer.sqrt(x-1), "10**#{i}-1")
end
+
+ bug13440 = '[ruby-core:80696] [Bug #13440]'
+ too_big = []
+ too_small = []
+ 0.step(to: 50, by: 0.001) do |i|
+ n = (10**i).to_i
+ int_root = Integer.sqrt(n)
+ too_big << n if int_root*int_root > n
+ too_small << n if (int_root+1)*(int_root+1) <= n
+ end
+ assert_empty(too_big, bug13440)
+ assert_empty(too_small, bug13440)
end
end