Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Array#sum and Enumerable#sum #4309

merged 4 commits into from Nov 17, 2016

fix Array#sum and Enumerable#sum #4309

merged 4 commits into from Nov 17, 2016


Copy link

This changes Array#sum and Enumerable#sum to use Kahan's compensated summation algorithm, so we have the same rounding artifacts as MRI.

It also includes some of the MRI's cascading coercion behaviour in Array#sum

Now all tests in test/mri/ruby/test_array.rb and test/mri/ruby/test_enum.rb pass, except for those depending on 'mathn' which I can't test because of an unrelated issue.

Consider this a regression fix for #4297

Fixes part of a bug identified in #4297
Fixes most of the tests that weren't perfect in #4297.
This passes the final MRI test, referenced in #4297
Copy link
Contributor Author

I'm not entirely comfortable that RubyArray is now an expert on Fixnum, Bignum, Rational and Float, but the behaviour matches MRI's.

Copy link

headius commented Nov 17, 2016

Looks good! Thank you!

@headius headius merged commit 46aca6c into jruby:ruby-2.4 Nov 17, 2016
@headius headius added this to the JRuby milestone Nov 17, 2016
@phluid61 phluid61 deleted the feature/optimise-enumerable-sum branch November 17, 2016 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants