diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-04 14:02:59 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-04 14:02:59 +0000 |
commit | 85bcd2b35f7f5b5627c8a64381c1859037696ff9 (patch) | |
tree | b4deb2725d50fd591744d669ed701a96a1dadc31 | |
parent | ab73022cb2357db5e757aed6a7c2f0c4268aa7c7 (diff) | |
download | ruby-85bcd2b35f7f5b5627c8a64381c1859037696ff9.tar.gz |
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
-rw-r--r-- | bignum.c | 4 | ||||
-rw-r--r-- | test/ruby/test_rational.rb | 1 |
2 files changed, 2 insertions, 3 deletions
@@ -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); diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index ae253d89fc..c44ff0393a 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -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 |