New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numeric#step yields Floats instead of Integers #5078

Closed
janko-m opened this Issue Mar 3, 2018 · 8 comments

Comments

Projects
None yet
4 participants
@janko-m

janko-m commented Mar 3, 2018

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]
@raphaeltelatim

This comment has been minimized.

raphaeltelatim commented Mar 13, 2018

@kares can I take this one?

@kares

This comment has been minimized.

Member

kares commented Mar 14, 2018

Sure Raphael, go for it ... 🐇

@headius

This comment has been minimized.

Member

headius commented Mar 15, 2018

Ugh. How is this not failing specs or tests?

@headius headius added this to the JRuby 9.1.17.0 milestone Mar 15, 2018

@headius

This comment has been minimized.

Member

headius commented Mar 15, 2018

Confirmed still broken in 9.1 HEAD.

@headius

This comment has been minimized.

Member

headius commented Mar 15, 2018

Confirmed still broken on master and jruby-9.1 HEAD.

@raphaeltelatim

This comment has been minimized.

raphaeltelatim commented Mar 16, 2018

@kares Ok, thanks

@headius

This comment has been minimized.

Member

headius commented Apr 12, 2018

@raphaeltelatim I'm going to tackle this one since we're getting close to 9.1.17 release time. If you started on it, let me know.

@headius headius closed this in acf72b1 Apr 12, 2018

headius added a commit that referenced this issue Apr 12, 2018

Update logic for Numeric#step from MRI 2.5. Fixes #5078
This includes the following changes:

* Re-port Numeric#step logic and related functions.
* Re-port Numeric#step enumerator size logic.
* Modify ArgsUtil.extractKeywordArgs to use UNDEF instead of nil.
* Update tags for Numeric, Fixnum, Bignum, Integer, Float (no
  changes for last two).
@headius

This comment has been minimized.

Member

headius commented Apr 12, 2018

I have fully updated the Numeric#step and Numeric#step enumerator size logic from MRI 2.3 (for 9.1) and MRI 2.5 (for 9.2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment