Project

General

Profile

Actions

Bug #14805

closed

Enumerator#count is silently limited to int32

Added by amadan (Goran Topic) over 6 years ago. Updated over 6 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin17]
[ruby-core:87340]

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
Actions #3

Updated by naruse (Yui NARUSE) over 6 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r63549.


memo->u3.cnt is long not int [Bug #14805]

Actions #4

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0