* enum.c (ary_inject_op): put subtract operation out of if-clause.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e324d29e2b
commit
aeb0be6ad5
|
@ -1,3 +1,7 @@
|
||||||
|
Wed Mar 23 21:48:00 2016 Kenta Murata <mrkn@mrkn.jp>
|
||||||
|
|
||||||
|
* enum.c (ary_inject_op): put subtract operation out of if-clause.
|
||||||
|
|
||||||
Wed Mar 23 21:38:00 2016 Kenta Murata <mrkn@mrkn.jp>
|
Wed Mar 23 21:38:00 2016 Kenta Murata <mrkn@mrkn.jp>
|
||||||
|
|
||||||
* enum.c (ary_inject_op): Use Kahan's compensated summation algorithm
|
* enum.c (ary_inject_op): Use Kahan's compensated summation algorithm
|
||||||
|
|
9
enum.c
9
enum.c
|
@ -688,17 +688,18 @@ ary_inject_op(VALUE ary, VALUE init, VALUE op)
|
||||||
sum_float:
|
sum_float:
|
||||||
c = 0.0;
|
c = 0.0;
|
||||||
while (1) {
|
while (1) {
|
||||||
double y, t;
|
double x, y, t;
|
||||||
e = RARRAY_AREF(ary, i);
|
e = RARRAY_AREF(ary, i);
|
||||||
if (RB_FLOAT_TYPE_P(e))
|
if (RB_FLOAT_TYPE_P(e))
|
||||||
y = RFLOAT_VALUE(e) - c;
|
x = RFLOAT_VALUE(e);
|
||||||
else if (FIXNUM_P(e))
|
else if (FIXNUM_P(e))
|
||||||
y = FIX2LONG(e) - c;
|
x = FIX2LONG(e);
|
||||||
else if (RB_TYPE_P(e, T_BIGNUM))
|
else if (RB_TYPE_P(e, T_BIGNUM))
|
||||||
y = rb_big2dbl(e) - c;
|
x = rb_big2dbl(e);
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
y = x - c;
|
||||||
t = f + y;
|
t = f + y;
|
||||||
c = (t - f) - y;
|
c = (t - f) - y;
|
||||||
f = t;
|
f = t;
|
||||||
|
|
Loading…
Reference in New Issue