ruby-changes:47865
From: nobu <ko1@a...>
Date: Fri, 22 Sep 2017 12:05:07 +0900 (JST)
Subject: [ruby-changes:47865] nobu:r59986 (trunk): numeric.c: use NUM2DBL
nobu 2017-09-22 12:05:02 +0900 (Fri, 22 Sep 2017) New Revision: 59986 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59986 Log: numeric.c: use NUM2DBL * numeric.c (fix_fdiv_double), bignum.c (rb_big_fdiv_double): use NUM2DBL on unknown object. RFLOAT_VALUE is only appliicable to T_FLOAT object. [ruby-core:82924] [Bug #13928] Modified files: trunk/bignum.c trunk/numeric.c trunk/test/ruby/test_bignum.rb trunk/test/ruby/test_integer.rb Index: bignum.c =================================================================== --- bignum.c (revision 59985) +++ bignum.c (revision 59986) @@ -6176,7 +6176,7 @@ rb_big_fdiv_double(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6176 return big_fdiv_float(x, y); } else { - return RFLOAT_VALUE(rb_num_coerce_bin(x, y, rb_intern("fdiv"))); + return NUM2DBL(rb_num_coerce_bin(x, y, rb_intern("fdiv"))); } return dx / dy; } Index: test/ruby/test_integer.rb =================================================================== --- test/ruby/test_integer.rb (revision 59985) +++ test/ruby/test_integer.rb (revision 59986) @@ -510,4 +510,19 @@ class TestInteger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_integer.rb#L510 end assert_empty(failures, bug13440) end + + def test_fdiv + assert_equal(1.0, 1.fdiv(1)) + assert_equal(0.5, 1.fdiv(2)) + end + + def test_obj_fdiv + o = Object.new + def o.coerce(x); [x, 0.5]; end + assert_equal(2.0, 1.fdiv(o)) + o = Object.new + def o.coerce(x); [self, x]; end + def o.fdiv(x); 1; end + assert_equal(1.0, 1.fdiv(o)) + end end Index: test/ruby/test_bignum.rb =================================================================== --- test/ruby/test_bignum.rb (revision 59985) +++ test/ruby/test_bignum.rb (revision 59986) @@ -693,6 +693,10 @@ class TestBignum < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_bignum.rb#L693 o = Object.new def o.coerce(x); [x, 2**100]; end assert_equal((2**200).to_f, (2**300).fdiv(o)) + o = Object.new + def o.coerce(x); [self, x]; end + def o.fdiv(x); 1; end + assert_equal(1.0, (2**300).fdiv(o)) end def test_singleton_method Index: numeric.c =================================================================== --- numeric.c (revision 59985) +++ numeric.c (revision 59986) @@ -3629,7 +3629,7 @@ fix_fdiv_double(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L3629 return (double)FIX2LONG(x) / RFLOAT_VALUE(y); } else { - return RFLOAT_VALUE(rb_num_coerce_bin(x, y, rb_intern("fdiv"))); + return NUM2DBL(rb_num_coerce_bin(x, y, rb_intern("fdiv"))); } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/