Project

General

Profile

Actions

Bug #15537

closed

Numeric#step doesn't iterate under some conditions

Added by shuujii (Shuji KOBAYASHI) 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-linux]
[ruby-core:91101]

Description

Numeric#step doesn't iterate under the following conditions:

  • receiver and/or by are Float
  • by is negative
  • to is default
  • without block

Example:

Good:

p 1.step(by: 3).take(2)                                     #=> [1, 4]
p 1.step(by: -3).take(2)                                    #=> [1, -2]
p 1.step(by: 3.0).take(2)                                   #=> [1.0, 4.0]
p 1.0.step(by: 3).take(2)                                   #=> [1.0, 4.0]
a=[]; p 1.step(by: -3.0){|n|break a if (a << n).size == 2}  #=> [1.0, -2.0]
a=[]; p 1.0.step(by: -3){|n|break a if (a << n).size == 2}  #=> [1.0, -2.0]

Bad:

p 1.step(by: -3.0).take(2)  #=> []
p 1.0.step(by: -3).take(2)  #=> []

I have attached a patch.


Files

fix-numeric-step-for-float.patch (2.07 KB) fix-numeric-step-for-float.patch shuujii (Shuji KOBAYASHI), 01/15/2019 10:13 AM

Updated by mrkn (Kenta Murata) about 5 years ago

  • Status changed from Open to Assigned
  • Assignee set to mrkn (Kenta Murata)
Actions #2

Updated by mrkn (Kenta Murata) about 5 years ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r66914.


numeric.c: Fix negative step with float components

  • numeric.c (ruby_float_step): fix negative step with float components.

  • test/ruby/test_numeric.c (test_step_bug15537): add tests.

  • test/ruby/test_range.c (test_step_bug15537): add tests.

[Bug #15537] [ruby-core:91101]

From: shuujii (Shuji KOBAYASHI)

Actions

Also available in: Atom PDF

Like0
Like0Like0