Skip to content
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 opened this issue Mar 3, 2018 · 8 comments
Closed

Numeric#step yields Floats instead of Integers #5078

janko opened this issue Mar 3, 2018 · 8 comments

Comments

@janko
Copy link

janko 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
Copy link

@kares can I take this one?

@kares
Copy link
Member

kares commented Mar 14, 2018

Sure Raphael, go for it ... 🐇

@headius
Copy link
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
Copy link
Member

headius commented Mar 15, 2018

Confirmed still broken in 9.1 HEAD.

@headius
Copy link
Member

headius commented Mar 15, 2018

Confirmed still broken on master and jruby-9.1 HEAD.

@raphaeltelatim
Copy link

@kares Ok, thanks

@headius
Copy link
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 added a commit that referenced this issue Apr 12, 2018
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
Copy link
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
Projects
None yet
Development

No branches or pull requests

4 participants