Project

General

Profile

Actions

Bug #8010

closed

Enumerator#with_index(large_number)

Added by znz (Kazuhiro NISHIYAMA) over 11 years ago. Updated almost 11 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.0dev (2013-03-04 trunk 39580) [x86_64-linux]
Backport:
[ruby-dev:47131]

Description

Enumerator#with_index の引数で大きな数を指定するとマイナスになったり例外になったりするのはバグでしょうか?

% ruby -ve 'p 3.times.with_index(1<<61).to_a'
ruby 2.1.0dev (2013-03-04 trunk 39580) [x86_64-linux]
[[0, 2305843009213693952], [1, 2305843009213693953], [2, 2305843009213693954]]
% ruby -ve 'p 3.times.with_index(1<<62).to_a'
ruby 2.1.0dev (2013-03-04 trunk 39580) [x86_64-linux]
[[0, -4611686018427387904], [1, -4611686018427387903], [2, -4611686018427387902]]
% ruby -ve 'p 3.times.with_index(1<<63).to_a'
ruby 2.1.0dev (2013-03-04 trunk 39580) [x86_64-linux]
-e:1:in with_index': bignum too big to convert into long' (RangeError)
from -e:1:in each' from -e:1:in to_a'
from -e:1:in `'

Actions #1

Updated by nobu (Nobuyoshi Nakada) over 11 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39594.
Kazuhiro, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


enumerator.c: allow Bignum for with_index

  • enumerator.c (enumerator_with_index_i): allow Bignum as offset, to
    get rid of conversion exception and integer overflow.
    [ruby-dev:47131] [Bug #8010]

Updated by nagachika (Tomoyuki Chikanaga) almost 11 years ago

r39594 and r39596 were backported to ruby_2_0_0 branch at 43960.

Updated by usa (Usaku NAKAMURA) almost 11 years ago

backported into ruby_1_9_3 at r44744.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0