diff options
author | Kenta Murata <[email protected]> | 2020-12-18 23:46:26 +0900 |
---|---|---|
committer | Kenta Murata <[email protected]> | 2020-12-19 22:13:53 +0900 |
commit | e1424c35012ccf1f3822c9046081b225aef4142e (patch) | |
tree | 8eb32ec210261bae5940d3af11b13903bcbb1112 /test | |
parent | 4735a5b9d2cbde69c501ee8d5bb570f4fac7e51d (diff) |
[bigdecimal] Fix the default precision of Float#to_d
Fix https://github.com/ruby/bigdecimal/issues/70
[Bug #13331]
https://github.com/ruby/bigdecimal/commit/aa536cd4b5
Diffstat (limited to 'test')
-rw-r--r-- | test/bigdecimal/test_bigdecimal_util.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/test/bigdecimal/test_bigdecimal_util.rb b/test/bigdecimal/test_bigdecimal_util.rb index 7c0830e96c..b855fd58a0 100644 --- a/test/bigdecimal/test_bigdecimal_util.rb +++ b/test/bigdecimal/test_bigdecimal_util.rb @@ -17,10 +17,12 @@ class TestBigDecimalUtil < Test::Unit::TestCase end def test_Float_to_d_without_precision - delta = 1.0/10**(Float::DIG) - assert_in_delta(BigDecimal(0.5, Float::DIG), 0.5.to_d, delta) - assert_in_delta(BigDecimal(355.0/113.0, Float::DIG), (355.0/113.0).to_d, delta) - assert_equal(9.05.to_d.to_s('F'), "9.05") + delta = 1.0/10**(Float::DIG+1) + assert_in_delta(BigDecimal(0.5, Float::DIG+1), 0.5.to_d, delta) + assert_in_delta(BigDecimal(355.0/113.0, Float::DIG+1), (355.0/113.0).to_d, delta) + + assert_equal(9.05, 9.05.to_d.to_f) + assert_equal("9.050000000000001", 9.05.to_d.to_s('F')) bug9214 = '[ruby-core:58858]' assert_equal((-0.0).to_d.sign, -1, bug9214) @@ -43,6 +45,12 @@ class TestBigDecimalUtil < Test::Unit::TestCase assert(1.1.to_d(digits).frozen?) end + def test_Float_to_d_bug13331 + assert_equal(64.4.to_d, + 1.to_d * 64.4, + "[ruby-core:80234] [Bug #13331]") + end + def test_Rational_to_d digits = 100 delta = 1.0/10**(digits) |