aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-01 15:02:47 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-01 15:02:47 +0000
commit78729a59a2ad0269b79655d7f6da8fe8175f25e2 (patch)
tree570aa93bcaab83e5c008ff78e997ce719571943b
parentb1376614deef85185f143c7fc799afe01429582a (diff)
downloadruby-78729a59a2ad0269b79655d7f6da8fe8175f25e2.tar.gz
Fix rb_ary_sum for mathn
* array.c (rb_ary_sum): fix for mathn * test/ruby/test_array.rb (test_sum): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--array.c22
-rw-r--r--test/ruby/test_array.rb4
3 files changed, 28 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index b1ec5e7ddd..125190443f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun May 1 23:59:59 2016 Kenta Murata <mrkn@mrkn.jp>
+
+ * array.c (rb_ary_sum): fix for mathn
+
+ * test/ruby/test_array.rb (test_sum): ditto.
+
Sun May 1 23:51:54 2016 NAKAMURA Usaku <usa@ruby-lang.org>
* test/lib/test/unit.rb (Options#non_options): fixed wrong regexp.
diff --git a/array.c b/array.c
index 5a0d8aa0e5..8b68320fa0 100644
--- a/array.c
+++ b/array.c
@@ -5732,15 +5732,29 @@ rb_ary_sum(int argc, VALUE *argv, VALUE ary)
}
if (n != 0)
v = rb_fix_plus(LONG2FIX(n), v);
- if (r != Qundef)
- v = rb_rational_plus(r, v);
+ if (r != Qundef) {
+ /* r can be a Integer when mathn is loaded */
+ if (FIXNUM_P(r))
+ v = rb_fix_plus(r, v);
+ else if (RB_TYPE_P(r, T_BIGNUM))
+ v = rb_big_plus(r, v);
+ else
+ v = rb_rational_plus(r, v);
+ }
return v;
not_exact:
if (n != 0)
v = rb_fix_plus(LONG2FIX(n), v);
- if (r != Qundef)
- v = rb_rational_plus(r, v);
+ if (r != Qundef) {
+ /* r can be a Integer when mathn is loaded */
+ if (FIXNUM_P(r))
+ v = rb_fix_plus(r, v);
+ else if (RB_TYPE_P(r, T_BIGNUM))
+ v = rb_big_plus(r, v);
+ else
+ v = rb_rational_plus(r, v);
+ }
if (RB_FLOAT_TYPE_P(e)) {
/* Kahan's compensated summation algorithm */
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 36f2b7d72d..44eec9143d 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -2789,6 +2789,10 @@ class TestArray < Test::Unit::TestCase
assert_equal("abc", ["a", "b", "c"].sum(""))
assert_equal([1, [2], 3], [[1], [[2]], [3]].sum([]))
+
+ assert_separately(%w[-rmathn], <<-EOS, ignore_stderr: true)
+ assert_equal(6, [1r, 2, 3r].sum)
+ EOS
end
private