summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-04 06:37:44 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-04 06:37:44 +0000
commit1699396fe502d929ced019dc0dd3463a35fbf6d3 (patch)
tree53749c797246de19f82c3d710ec1f753e01d6315
parentdd87e463106ade202e3b04e7703a91e438c027d6 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--ext/bigdecimal/lib/bigdecimal/util.rb2
-rw-r--r--test/bigdecimal/test_bigdecimal_util.rb7
3 files changed, 13 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index dc3debf356a..5ae31b50280 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 b27e64c5113..bd02ef427cb 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 72342b922fb..9a5d504abd7 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