summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-06-15 10:40:52 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2020-06-29 11:05:41 +0900
commitc47b805d8cf28d105139b422ed2d30c5e0617a29 (patch)
tree52270108ca1098c52fb746eead3ecfa9d28e4bc7 /enum.c
parentd060ebf83c74b79fd8315e6428bad53a0b0d3fce (diff)
add spaces [ci skip]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3247
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/enum.c b/enum.c
index f72a64f..8769680 100644
--- a/enum.c
+++ b/enum.c
@@ -3853,6 +3853,7 @@ sum_iter_normalize_memo(struct enum_sum_memo *memo)
assert(FIXABLE(memo->n));
memo->v = rb_fix_plus(LONG2FIX(memo->n), memo->v);
memo->n = 0;
+
/* r can be an Integer when mathn is loaded */
switch (TYPE(memo->r)) {
case T_FIXNUM: memo->v = rb_fix_plus(memo->r, memo->v); break;
@@ -3863,6 +3864,7 @@ sum_iter_normalize_memo(struct enum_sum_memo *memo)
}
memo->r = Qundef;
}
+
static void
sum_iter_fixnum(VALUE i, struct enum_sum_memo *memo)
{
@@ -3872,11 +3874,13 @@ sum_iter_fixnum(VALUE i, struct enum_sum_memo *memo)
memo->n = 0;
}
}
+
static void
sum_iter_bignum(VALUE i, struct enum_sum_memo *memo)
{
memo->v = rb_big_plus(i, memo->v);
}
+
static void
sum_iter_rational(VALUE i, struct enum_sum_memo *memo)
{
@@ -3887,11 +3891,13 @@ sum_iter_rational(VALUE i, struct enum_sum_memo *memo)
memo->r = rb_rational_plus(memo->r, i);
}
}
+
static void
sum_iter_some_value(VALUE i, struct enum_sum_memo *memo)
{
memo->v = rb_funcallv(memo->v, idPLUS, 1, &i);
}
+
static void
sum_iter_Kahan_Babuska(VALUE i, struct enum_sum_memo *memo)
{
@@ -3900,6 +3906,7 @@ sum_iter_Kahan_Babuska(VALUE i, struct enum_sum_memo *memo)
* See http://link.springer.com/article/10.1007/s00607-005-0139-x
*/
double x;
+
switch (TYPE(i)) {
case T_FLOAT: x = RFLOAT_VALUE(i); break;
case T_FIXNUM: x = FIX2LONG(i); break;
@@ -3911,7 +3918,9 @@ sum_iter_Kahan_Babuska(VALUE i, struct enum_sum_memo *memo)
sum_iter_some_value(i, memo);
return;
}
+
double f = memo->f;
+
if (isnan(f)) {
return;
}
@@ -3927,8 +3936,10 @@ sum_iter_Kahan_Babuska(VALUE i, struct enum_sum_memo *memo)
else if (isinf(f)) {
return;
}
+
double c = memo->c;
double t = f + x;
+
if (fabs(f) >= fabs(x)) {
c += ((f - t) + x);
}
@@ -3936,9 +3947,11 @@ sum_iter_Kahan_Babuska(VALUE i, struct enum_sum_memo *memo)
c += ((x - t) + f);
}
f = t;
+
memo->f = f;
memo->c = c;
}
+
static void
sum_iter(VALUE i, struct enum_sum_memo *memo)
{
@@ -3946,6 +3959,7 @@ sum_iter(VALUE i, struct enum_sum_memo *memo)
if (memo->block_given) {
i = rb_yield(i);
}
+
if (memo->float_value) {
sum_iter_Kahan_Babuska(i, memo);
}