diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-07-22 10:47:33 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-07-22 10:47:33 +0000 |
commit | 67cacdb83610889d1153409362cc38448affb4e8 (patch) | |
tree | a894254777fedfb7d3c23438796882301c5b3295 /array.c | |
parent | b22352af91b13512301103d8d1b73bc999186225 (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 'array.c')
-rw-r--r-- | array.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -5973,6 +5973,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); |