summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-01 02:31:27 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-01 02:31:27 +0000
commit2c26edc15c4d30494601d5df11daea4a26a38465 (patch)
tree83ae2e48eb7bfcc99a8e54be82ea76f2ecf05c7f /array.c
parentf63697432e6214e4be3c38648d71ccffaa0c7545 (diff)
merge revision(s) 64014: [Backport #14926]
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/branches/ruby_2_5@64603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/array.c b/array.c
index fa88f47ae9..b40f05e76d 100644
--- a/array.c
+++ b/array.c
@@ -5954,6 +5954,20 @@ rb_ary_sum(int argc, VALUE *argv, VALUE ary)
else
goto not_float;
+ if (isnan(f)) continue;
+ if (isnan(x)) {
+ f = x;
+ continue;
+ }
+ if (isinf(x)) {
+ if (isinf(f) && signbit(x) != signbit(f))
+ f = NAN;
+ else
+ f = x;
+ continue;
+ }
+ if (isinf(f)) continue;
+
t = f + x;
if (fabs(f) >= fabs(x))
c += ((f - t) + x);