summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-27 14:11:19 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-27 14:11:19 +0000
commitba757763464cb3cd344454bb8d8e062ca92d2a3d (patch)
treeb7a832a8b1049393093d8f340952e2d6b32b48b8 /array.c
parent95abe79e04c3238ea2dde68ea1ab567e354aad21 (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_4@64562 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 724cf46b38..35c63fe857 100644
--- a/array.c
+++ b/array.c
@@ -5825,6 +5825,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);