diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-06 13:40:31 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-12-06 13:40:31 +0000 |
commit | 48f5f5915b0c357b05a9dda2732470bf67ebd691 (patch) | |
tree | 770f8065f1ef2a61f38cc5941334b759f43172f9 /test | |
parent | 0cb1a2b81232b5a64242fc6899d72be22b35495f (diff) | |
download | ruby-48f5f5915b0c357b05a9dda2732470bf67ebd691.tar.gz |
array.c, enum.c: change sum algorithm
* array.c (rb_ary_sum): change the algorithm to Kahan-Babuska balancing
summation to be more precise.
[Feature #12871] [ruby-core:77771]
* enum.c (sum_iter, enum_sum): ditto.
* test_array.rb, test_enum.rb: add an assertion for the above change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_array.rb | 1 | ||||
-rw-r--r-- | test/ruby/test_enum.rb | 1 |
2 files changed, 2 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 24a8eae346..5ecaaa3aa6 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -2821,6 +2821,7 @@ class TestArray < Test::Unit::TestCase assert_float_equal(large_number+(small_number*10), [large_number, *[small_number]*10].sum) assert_float_equal(large_number+(small_number*10), [large_number/1r, *[small_number]*10].sum) assert_float_equal(large_number+(small_number*11), [small_number, large_number/1r, *[small_number]*10].sum) + assert_float_equal(small_number, [large_number, small_number, -large_number].sum) assert_equal("abc", ["a", "b", "c"].sum("")) assert_equal([1, [2], 3], [[1], [[2]], [3]].sum([])) diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index 4ff4f88ca9..c70ec7ceba 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -903,6 +903,7 @@ class TestEnumerable < Test::Unit::TestCase assert_float_equal(large_number+(small_number*10), [large_number, *[small_number]*10].each.sum) assert_float_equal(large_number+(small_number*10), [large_number/1r, *[small_number]*10].each.sum) assert_float_equal(large_number+(small_number*11), [small_number, large_number/1r, *[small_number]*10].each.sum) + assert_float_equal(small_number, [large_number, small_number, -large_number].each.sum) assert_equal("abc", ["a", "b", "c"].each.sum("")) assert_equal([1, [2], 3], [[1], [[2]], [3]].each.sum([])) |