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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2018-04-04 14:02:59 +00:00
Родитель ab73022cb2
Коммит 85bcd2b35f
2 изменённых файлов: 2 добавлений и 3 удалений

Просмотреть файл

@ -6178,9 +6178,7 @@ rb_big_fdiv_double(VALUE x, VALUE y)
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);

Просмотреть файл

@ -837,6 +837,7 @@ class Rational_Test < Test::Unit::TestCase
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