Project

General

Profile

Actions

Bug #15518

closed

good old Infinite range notation behavior

Added by sakuro (Sakuro OZAWA) over 5 years ago. Updated about 5 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin18]
[ruby-core:90937]

Description

Ruby 2.5.3's behavior

# without step, it produces integer sequence
(1..Float::INFINITY).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# with step, it produces floats instead of integers
(1..Float::INFINITY).step(1).first(10) #=> [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]

Ruby 2.6.0's behavior

# endless range
(1..).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# with step, all numbers are integer now
(1..).step(1).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# old idiom with Float::INFINITY
(1..Float::INFINITY).first(10) #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
(1..Float::INFINITY).step(1).first(10) #=> FloatDomainError (Infinity)

Which are intended change and which are not?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0