Actions
Bug #14805
closedEnumerator#count is silently limited to int32
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin17]
Backport:
Description
One takes for granted that integers will be promoted into bigints in Ruby when needed.
Not so with Enumerator#count
:
2147483647.times.count
# => 2147483647
2147483648.times.count
# => -2147483648
(notice the minus!)
Updated by duerst (Martin Dürst) over 6 years ago
Confirmed on trunk.
Updated by shan (Shannon Skipper) over 6 years ago
It's interestingly also negative on JRuby. Headius noted in the #ruby IRC channel that this patch would fix the issue for JRuby.
It's positive in TruffleRuby.
It's also positive in Rubinius, but takes about half and hour to calculate and uses ~5GB of RAM. :-O Not sure what's going on there.
On the non-Ruby front, it's negative in Crystal-lang too!
2147483648.times.count { |n| n } #=> -2147483648 : Int32
Updated by naruse (Yui NARUSE) over 6 years ago
- Status changed from Open to Closed
Updated by naruse (Yui NARUSE) over 6 years ago
- Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.3: REQUIRED, 2.4: REQUIRED, 2.5: REQUIRED
Updated by usa (Usaku NAKAMURA) over 6 years ago
- Backport changed from 2.3: REQUIRED, 2.4: REQUIRED, 2.5: REQUIRED to 2.3: REQUIRED, 2.4: DONE, 2.5: REQUIRED
ruby_2_4 r64125 merged revision(s) 63549,63551,63554.
Updated by nagachika (Tomoyuki Chikanaga) over 6 years ago
- Backport changed from 2.3: REQUIRED, 2.4: DONE, 2.5: REQUIRED to 2.3: REQUIRED, 2.4: DONE, 2.5: DONE
ruby_2_5 r64432 merged revision(s) 63549,63551,63554.
Actions
Like0
Like0Like0Like0Like0Like0Like0