Skip to content

Numeric#step yields Floats instead of Integers #5078

@janko

Description

@janko

Environment

$ jruby -v
jruby 9.1.15.0 (2.3.3) 2017-12-07 929fde8 Java HotSpot(TM) 64-Bit Server VM 25.40-b25 on 1.8.0_40-b27 +jit [darwin-x86_64]
$ uname -a 
Darwin Jankos-MacBook-Pro-2.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64

Expected Behavior

When I call Numeric#step on an Integer with an Integer step, MRI yields Integers:

# with default step of 1
1.step.first(5)
#=> [1, 2, 3, 4, 5]

# with explicit step
1.step(by: 2).first(5)
#=> [1, 3, 5, 7, 9]

On the other hand, when either the receiver or the step is a Float, MRI yields Floats:

# with default step of 1
1.0.step.first(5)
#=> [1.0, 2.0, 3.0, 4.0, 5.0]

# with explicit step
1.step(by: 1.0).first(5)
#=> [1.0, 2.0, 3.0, 4.0, 5.0]

Actual Behavior

On JRuby Numeric#step yields Floats regardless of whether the receiver and step are Integers or Floats:

1.step.first(5)
#=> [1.0, 2.0, 3.0, 4.0, 5.0]

1.step(by: 2).first(5)
#=> [1.0, 3.0, 5.0, 7.0, 9.0]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions