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

ruby-changes:44263

From: nobu <ko1@a...>
Date: Tue, 4 Oct 2016 09:55:23 +0900 (JST)
Subject: [ruby-changes:44263] nobu:r56336 (trunk): bigdecimal.c: more precision

nobu	2016-10-04 09:55:15 +0900 (Tue, 04 Oct 2016)

  New Revision: 56336

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56336

  Log:
    bigdecimal.c: more precision
    
    * ext/bigdecimal/bigdecimal.c (BigDecimal_div2): need more room
      for precision to round.  [ruby-core:77475] [Bug #12805]

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/bigdecimal.c
    trunk/test/bigdecimal/test_bigdecimal.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56335)
+++ ChangeLog	(revision 56336)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Oct  4 09:55:12 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/bigdecimal/bigdecimal.c (BigDecimal_div2): need more room
+	  for precision to round.  [ruby-core:77475] [Bug #12805]
+
 Tue Oct  4 06:05:46 2016  NARUSE, Yui  <naruse@r...>
 
 	* regcomp.c (onig_print_compiled_byte_code): make the shown address
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 56335)
+++ ext/bigdecimal/bigdecimal.c	(revision 56336)
@@ -1533,7 +1533,7 @@ BigDecimal_div2(VALUE self, VALUE b, VAL https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1533
         size_t mx = ix + VpBaseFig()*2;
         size_t pl = VpSetPrecLimit(0);
 
-        GUARD_OBJ(cv, VpCreateRbObject(mx, "0"));
+        GUARD_OBJ(cv, VpCreateRbObject(mx + VpBaseFig(), "0"));
         GUARD_OBJ(av, GetVpValue(self, 1));
         GUARD_OBJ(bv, GetVpValue(b, 1));
         mx = av->Prec + bv->Prec + 2;
Index: test/bigdecimal/test_bigdecimal.rb
===================================================================
--- test/bigdecimal/test_bigdecimal.rb	(revision 56335)
+++ test/bigdecimal/test_bigdecimal.rb	(revision 56336)
@@ -807,6 +807,12 @@ class TestBigDecimal < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L807
       BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, false)
       assert_equal(0, BigDecimal("0").div(BigDecimal("Infinity")))
     end
+
+    x = BigDecimal.new("1")
+    y = BigDecimal.new("0.22")
+    (2..20).each do |i|
+      assert_equal ("0."+"45"*(i/2)+"5"*(i%2)+"E1"), x.div(y, i).to_s, "#{i}"
+    end
   end
 
   def test_abs_bigdecimal

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

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