summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
Diffstat (limited to 'array.c')
-rw-r--r--array.c22
1 files changed, 18 insertions, 4 deletions
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 */