зеркало из https://github.com/github/ruby.git
array.c: finish_exact_sum
* array.c (finish_exact_sum): extract duplicate code from rb_ary_sum. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57649 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
3d031cea42
Коммит
7dccda437b
41
array.c
41
array.c
|
@ -5733,6 +5733,23 @@ rb_ary_dig(int argc, VALUE *argv, VALUE self)
|
|||
return rb_obj_dig(argc, argv, self, Qnil);
|
||||
}
|
||||
|
||||
static inline VALUE
|
||||
finish_exact_sum(long n, VALUE r, VALUE v)
|
||||
{
|
||||
if (n != 0)
|
||||
v = rb_fix_plus(LONG2FIX(n), v);
|
||||
if (r != Qundef) {
|
||||
/* r can be an 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;
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* ary.sum(init=0) -> number
|
||||
|
@ -5814,31 +5831,11 @@ rb_ary_sum(int argc, VALUE *argv, VALUE ary)
|
|||
else
|
||||
goto not_exact;
|
||||
}
|
||||
if (n != 0)
|
||||
v = rb_fix_plus(LONG2FIX(n), v);
|
||||
if (r != Qundef) {
|
||||
/* r can be an 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);
|
||||
}
|
||||
v = finish_exact_sum(n, r, v);
|
||||
return v;
|
||||
|
||||
not_exact:
|
||||
if (n != 0)
|
||||
v = rb_fix_plus(LONG2FIX(n), v);
|
||||
if (r != Qundef) {
|
||||
/* r can be an 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);
|
||||
}
|
||||
v = finish_exact_sum(n, r, v);
|
||||
|
||||
if (RB_FLOAT_TYPE_P(e)) {
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче