diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-10-20 21:57:05 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-10-20 21:57:05 +0200 |
commit | 030b1892d5cc6f4c14b08d67d4ee60c202edc183 (patch) | |
tree | 8868c9c180b2c24d22ba13e00e6137007a60290f /spec/ruby/core/enumerable | |
parent | 500ba248826fea96c93dbc76199dd331f0a43eb2 (diff) | |
download | ruby-030b1892d5cc6f4c14b08d67d4ee60c202edc183.tar.gz |
Update to ruby/spec@254c380
Diffstat (limited to 'spec/ruby/core/enumerable')
-rw-r--r-- | spec/ruby/core/enumerable/sum_spec.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/spec/ruby/core/enumerable/sum_spec.rb b/spec/ruby/core/enumerable/sum_spec.rb index c9d7017b45..4a978794e5 100644 --- a/spec/ruby/core/enumerable/sum_spec.rb +++ b/spec/ruby/core/enumerable/sum_spec.rb @@ -25,4 +25,13 @@ describe 'Enumerable#sum' do it 'takes a block to transform the elements' do @enum.sum { |element| element * 2 }.should == 10/3r end + + # https://bugs.ruby-lang.org/issues/12217 + # https://github.com/ruby/ruby/blob/master/doc/ChangeLog-2.4.0#L6208-L6214 + it "uses Kahan's compensated summation algorithm for precise sum of float numbers" do + floats = [2.7800000000000002, 5.0, 2.5, 4.44, 3.89, 3.89, 4.44, 7.78, 5.0, 2.7800000000000002, 5.0, 2.5].to_enum + naive_sum = floats.reduce { |sum, e| sum + e } + naive_sum.should == 50.00000000000001 + floats.sum.should == 50.0 + end end |