[前][次][番号順一覧][スレッド一覧]

ruby-changes:29006

From: mrkn <ko1@a...>
Date: Tue, 4 Jun 2013 15:37:59 +0900 (JST)
Subject: [ruby-changes:29006] mrkn:r41058 (trunk): * ext/bigdecimal/lib/bigdecimal/util.rb (Float#to_d): fix the number

mrkn	2013-06-04 15:37:44 +0900 (Tue, 04 Jun 2013)

  New Revision: 41058

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41058

  Log:
    * ext/bigdecimal/lib/bigdecimal/util.rb (Float#to_d): fix the number
      of figures.  Patch by Vipul A M <vipulnsward@g...>.
      https://github.com/ruby/ruby/pull/323  fix GH-323
    
    * test/bigdecimal/test_bigdecimal_util.rb: fix for the above change.

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/lib/bigdecimal/util.rb
    trunk/test/bigdecimal/test_bigdecimal_util.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41057)
+++ ChangeLog	(revision 41058)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jun  4 15:30:00 2013  Kenta Murata  <mrkn@c...>
+
+	* ext/bigdecimal/lib/bigdecimal/util.rb (Float#to_d): fix the number
+	  of figures.  Patch by Vipul A M <vipulnsward@g...>.
+	  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@m...>
 
 	* test/fileutils/test_fileutils.rb (TestFileUtils#test_mkdir): add
Index: ext/bigdecimal/lib/bigdecimal/util.rb
===================================================================
--- ext/bigdecimal/lib/bigdecimal/util.rb	(revision 41057)
+++ ext/bigdecimal/lib/bigdecimal/util.rb	(revision 41058)
@@ -28,7 +28,7 @@ class Float < Numeric https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/util.rb#L28
   #     # => #<BigDecimal:1dc69e0,'0.5E0',9(18)>
   #
   def to_d(precision=nil)
-    BigDecimal(self, precision || Float::DIG+1)
+    BigDecimal(self, precision || Float::DIG)
   end
 end
 
Index: test/bigdecimal/test_bigdecimal_util.rb
===================================================================
--- test/bigdecimal/test_bigdecimal_util.rb	(revision 41057)
+++ test/bigdecimal/test_bigdecimal_util.rb	(revision 41058)
@@ -14,9 +14,10 @@ class TestBigDecimalUtil < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal_util.rb#L14
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]