Project

General

Profile

Actions

Bug #14926

closed

Different results between Enumerable#sum and #reduce when Float::INFINITY present

Added by swistak35 (Rafał Łasocha) almost 6 years ago. Updated over 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
[ruby-core:88024]

Description

When Float::INFINITY is present in array, Enumerable#sum and Enumerable#reduce(0, &:+) are giving different results.

puts [Float::INFINITY].sum
puts [Float::INFINITY].reduce(0, &:+)

results in

NaN
Infinity

And I would expect both of them to be Infinity (meaning: #sum is working incorrectly).

Checked on ruby 2.5.1p57 and ruby 2.4.3p205, both have the same bug.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0