Project

General

Profile

Bug #12485 ยป rational-denom-to_int.patch

jeremyevans0 (Jeremy Evans), 07/25/2019 03:28 PM

View differences:

rational.c
2575 2575
        a1 = string_to_r_strict(a1, raise);
2576 2576
        if (!raise && NIL_P(a1)) return Qnil;
2577 2577
    }
2578
    else if (!rb_respond_to(a1, idTo_r) && rb_respond_to(a1, rb_intern("to_int"))) {
2579
        a1 = rb_to_int(a1);
2580
    }
2578 2581

  
2579 2582
    if (RB_FLOAT_TYPE_P(a2)) {
2580 2583
        a2 = float_to_r(a2);
......
2583 2586
        a2 = string_to_r_strict(a2, raise);
2584 2587
        if (!raise && NIL_P(a2)) return Qnil;
2585 2588
    }
2589
    else if (a2 != Qundef && !rb_respond_to(a2, idTo_r) && rb_respond_to(a2, rb_intern("to_int"))) {
2590
        a2 = rb_to_int(a2);
2591
    }
2586 2592

  
2587 2593
    if (RB_TYPE_P(a1, T_RATIONAL)) {
2588 2594
        if (a2 == Qundef || (k_exact_one_p(a2)))
test/ruby/test_rational.rb
158 158
    if (1.0/0).infinite?
159 159
      assert_raise(FloatDomainError){Rational(1.0/0)}
160 160
    end
161

  
162
    o = Object.new
163
    def o.to_int; 1; end
164
    assert_equal(1, Rational(o, 1))
165
    assert_equal(1, Rational(1, o))
166
    assert_equal(1, Rational(o, o))
161 167
  end
162 168

  
163 169
  def test_attr
164
-