Skip to content

Commit

Permalink
* ext/bigdecimal/lib/bigdecimal/util.rb (Float#to_d): fix the number
Browse files Browse the repository at this point in the history
  of figures.  Patch by Vipul A M <vipulnsward@gmail.com>.
  #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
  • Loading branch information
mrkn committed Jun 4, 2013
1 parent dd87e46 commit 1699396
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ext/bigdecimal/lib/bigdecimal/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions test/bigdecimal/test_bigdecimal_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def test_Integer_to_d
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
Expand Down

0 comments on commit 1699396

Please sign in to comment.