diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-01 15:02:47 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-01 15:02:47 +0000 |
commit | 5e0e0d00ff9af7e8bf0c78628db4690c65c82b02 (patch) | |
tree | 570aa93bcaab83e5c008ff78e997ce719571943b /array.c | |
parent | 94968b04fdcfd009cda146135c4d8b1fce834042 (diff) | |
download | ruby-5e0e0d00ff9af7e8bf0c78628db4690c65c82b02.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
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -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 */ |