diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | ext/bigdecimal/lib/bigdecimal/util.rb | 2 | ||||
-rw-r--r-- | test/bigdecimal/test_bigdecimal_util.rb | 7 |
3 files changed, 13 insertions, 4 deletions
@@ -1,3 +1,11 @@ +Tue Jun 4 15:30:00 2013 Kenta Murata <mrkn@cookpad.com> + + * ext/bigdecimal/lib/bigdecimal/util.rb (Float#to_d): fix the number + of figures. Patch by Vipul A M <vipulnsward@gmail.com>. + https://github.com/ruby/ruby/pull/323 fix GH-323 + + * test/bigdecimal/test_bigdecimal_util.rb: fix for the above change. + Tue Jun 4 00:44:27 2013 Kazuhiro NISHIYAMA <zn@mbf.nifty.com> * test/fileutils/test_fileutils.rb (TestFileUtils#test_mkdir): add diff --git a/ext/bigdecimal/lib/bigdecimal/util.rb b/ext/bigdecimal/lib/bigdecimal/util.rb index b27e64c511..bd02ef427c 100644 --- a/ext/bigdecimal/lib/bigdecimal/util.rb +++ b/ext/bigdecimal/lib/bigdecimal/util.rb @@ -28,7 +28,7 @@ class Float < Numeric # # => #<BigDecimal:1dc69e0,'0.5E0',9(18)> # def to_d(precision=nil) - BigDecimal(self, precision || Float::DIG+1) + BigDecimal(self, precision || Float::DIG) end end diff --git a/test/bigdecimal/test_bigdecimal_util.rb b/test/bigdecimal/test_bigdecimal_util.rb index 72342b922f..9a5d504abd 100644 --- a/test/bigdecimal/test_bigdecimal_util.rb +++ b/test/bigdecimal/test_bigdecimal_util.rb @@ -14,9 +14,10 @@ class TestBigDecimalUtil < Test::Unit::TestCase end def test_Float_to_d_without_precision - 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) + 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") end def test_Float_to_d_with_precision |