Project

General

Profile

Bug #15518

Updated by sakuro (Sakuro OZAWA) almost 6 years ago

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? 

Back