ruby-changes:50886
From: mame <ko1@a...>
Date: Wed, 4 Apr 2018 23:03:05 +0900 (JST)
Subject: [ruby-changes:50886] mame:r63093 (trunk): bignum.c: Bignum#fdiv avoids double division when divisor is bignum
mame 2018-04-04 23:02:59 +0900 (Wed, 04 Apr 2018) New Revision: 63093 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63093 Log: bignum.c: Bignum#fdiv avoids double division when divisor is bignum `Rational(int, bignum).to_f` sometimes returned a wrong result because `Bignum#div` casted its divisor to double. [Bug #14637] [ruby-core:86330] Modified files: trunk/bignum.c trunk/test/ruby/test_rational.rb Index: bignum.c =================================================================== --- bignum.c (revision 63092) +++ bignum.c (revision 63093) @@ -6178,9 +6178,7 @@ rb_big_fdiv_double(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6178 return big_fdiv_int(x, rb_int2big(FIX2LONG(y))); } else if (RB_BIGNUM_TYPE_P(y)) { - dy = rb_big2dbl(y); - if (isinf(dx) || isinf(dy)) - return big_fdiv_int(x, y); + return big_fdiv_int(x, y); } else if (RB_FLOAT_TYPE_P(y)) { dy = RFLOAT_VALUE(y); Index: test/ruby/test_rational.rb =================================================================== --- test/ruby/test_rational.rb (revision 63092) +++ test/ruby/test_rational.rb (revision 63093) @@ -837,6 +837,7 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L837 def test_to_f assert_equal(1.5, Rational(3,2).to_f) assert_equal(1.5, Float(Rational(3,2))) + assert_equal(1e-23, Rational(1, 10**23).to_f, "Bug #14637") end def test_to_c -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/