summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-22 10:47:33 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-22 10:47:33 (GMT)
commit67cacdb83610889d1153409362cc38448affb4e8 (patch)
treea894254777fedfb7d3c23438796882301c5b3295 /enum.c
parentb22352af91b13512301103d8d1b73bc999186225 (diff)
fix sum on infinity
* array.c (rb_ary_sum): consider non-finite floats. [ruby-core:88024] [Bug #14926] * enum.c (sum_iter): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/enum.c b/enum.c
index e57fa5e..04b6c9c 100644
--- a/enum.c
+++ b/enum.c
@@ -3809,6 +3809,25 @@ sum_iter(VALUE i, struct enum_sum_memo *memo)
goto some_value;
}
+ if (isnan(f)) return;
+ if (isnan(x)) {
+ memo->v = i;
+ memo->f = x;
+ return;
+ }
+ if (isinf(x)) {
+ if (isinf(f) && signbit(x) != signbit(f)) {
+ memo->f = NAN;
+ memo->v = DBL2NUM(f);
+ }
+ else {
+ memo->f = x;
+ memo->v = i;
+ }
+ return;
+ }
+ if (isinf(f)) return;
+
t = f + x;
if (fabs(f) >= fabs(x))
c += ((f - t) + x);