Issue Type: Bug Bug
Affects Versions: JRuby 1.7.0
Assignee: Unassigned
Components: Core Classes/Modules
Created: 03/Dec/12 4:30 PM
Description:

JRuby is not currently consistent with MRI.1.9.3,
and in turn MRI.1.9.3 isn't entirely consistent
between behaviour of finite and infinite step values.
In MRI.1.9.3:
(5.0...5.0).step(8.0) {|v| p v} # yields no values
(5.0...5.0).step(1.0 / 0.0) {|v| pv} # yields 5.0
There is a patch after the Ruby code:
I've tested the patch in JRuby.1.7.0.
Patch brings JRuby up to MRI.1.9.3,
and puts JRuby where I think MRI.1.9.3 ought to be.

def test_float_step(begv, endv, stepv)
rv = "stepv= #{stepv};"
itvs = []; begv.step(endv, stepv) {|v| itvs << v}
rv << "(#{begv}).step(#{endv}, stepv) its: #{itvs.inspect};"
itvs = []; rr = (begv..endv); rr.step(stepv) {|v| itvs << v}
rv << "(#{rr).step(stepv) its: #{itvs.inspect};"
itvs = []; rr = (begv...endv); rr.step(stepv) {|v| itvs << v}
rv << "(#{rr).step(stepv) its: #{itvs.inspect};"
puts rv
end

puts
test_float_step 5.0, 7.0, 8.0
test_float_step 5.0, 7.0, 1.0 / 0.0
test_float_step 5.0, 5.0, 8.0

  1. MRI problem with (5.0...5.0).step(1.0 / 0.0)
    test_float_step 5.0, 5.0, 1.0 / 0.0
    test_float_step 5.0, 3.0, 8.0
    test_float_step 5.0, 3.0, 1.0 / 0.0
    if 1==0
    puts
    test_float_step 5.0, 7.0, -8.0
    test_float_step 5.0, 7.0, -1.0 / 0.0
    test_float_step 5.0, 5.0, -8.0
    test_float_step 5.0, 5.0, -1.0 / 0.0
    test_float_step 5.0, 3.0, -8.0
    test_float_step 5.0, 3.0, -1.0 / 0.0
    end
    puts

*****************************************
RubyNumeric.java

static void floatStep19(ThreadContext context, Ruby runtime, IRubyObject from, IRubyObject to, IRubyObject step, boolean excl, Block block) {
...
if (Double.isInfinite(unit)) {
//- if (unit > 0) block.yield(context, RubyFloat.newFloat(runtime, beg)); //-
//+ To be consistent with MRI.1.9.3:
// if (unit > 0 ? beg <= end : beg >= end) { // block.yield(context, RubyFloat.newFloat(runtime, beg)); // }
//+ Following patch assumes MRI changes to full consistency:
if (excl ? (unit > 0 ? beg < end : beg > end) : //+
(unit > 0 ? beg <= end : beg >= end)) { //+ block.yield(context, RubyFloat.newFloat(runtime, beg)); //+ } //+
} else {

Environment: Windows, but it's a problem with the code in RubyNumeric.java
Project: JRuby
Priority: Minor Minor
Reporter: Colin Bartlett
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply via email to