diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-15 15:29:09 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-15 15:29:09 +0000 |
commit | df76f366a7be0a10deb4ab475ec4c5966d975ce2 (patch) | |
tree | c401b290b4b11c7abd30e45b33d35f8af41a0684 /test | |
parent | 5fb0f3f0220dfcbde3cbd8166d80fcd0916e041b (diff) | |
download | ruby-df76f366a7be0a10deb4ab475ec4c5966d975ce2.tar.gz |
bignum.c: fix inexact estimation
* bignum.c (estimate_initial_sqrt): estimated square root is
inexact if it is not equal to its ceil, needs Newton's method.
[ruby-core:80696] [Bug #13440]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_integer.rb | 12 |
1 files changed, 12 insertions, 0 deletions
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 |