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

ruby-changes:32509

From: mrkn <ko1@a...>
Date: Tue, 14 Jan 2014 02:30:05 +0900 (JST)
Subject: [ruby-changes:32509] mrkn:r44588 (trunk): * ext/bigdecimal/bigdecimal.c (BigDecimal_divide): Add an additional

mrkn	2014-01-14 02:29:58 +0900 (Tue, 14 Jan 2014)

  New Revision: 44588

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

  Log:
    * ext/bigdecimal/bigdecimal.c (BigDecimal_divide): Add an additional
      digit for the quotient to be compatible with bigdecimal 1.2.1 and
      the former.  [ruby-core:59365] [#9316] [#9305]
    
    * test/bigdecimal/test_bigdecimal.rb: tests for the above change.
    
    * ext/bigdecimal/bigdecimal.gemspec: bigdecimal version 1.2.4.

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/bigdecimal.c
    trunk/ext/bigdecimal/bigdecimal.gemspec
    trunk/test/bigdecimal/test_bigdecimal.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44587)
+++ ChangeLog	(revision 44588)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jan 14 02:20:00 2014  Kenta Murata  <mrkn@m...>
+
+	* ext/bigdecimal/bigdecimal.c (BigDecimal_divide): Add an additional
+	  digit for the quotient to be compatible with bigdecimal 1.2.1 and
+	  the former.  [ruby-core:59365] [#9316] [#9305]
+
+	* test/bigdecimal/test_bigdecimal.rb: tests for the above change.
+
+	* ext/bigdecimal/bigdecimal.gemspec: bigdecimal version 1.2.4.
+
 Mon Jan 13 14:55:31 2014  Zachary Scott  <e@z...>
 
 	* lib/xmlrpc/client.rb: [DOC] Remove note about SSL package on RAA
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 44587)
+++ ext/bigdecimal/bigdecimal.c	(revision 44588)
@@ -1222,8 +1222,10 @@ BigDecimal_divide(Real **c, Real **res, https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1222
 
     *div = b;
     mx = a->Prec + vabs(a->exponent);
-    if (mx<b->Prec + vabs(b->exponent)) mx = b->Prec + vabs(b->exponent);
-    mx =(mx + 1) * VpBaseFig();
+    if (mx < b->Prec + vabs(b->exponent)) mx = b->Prec + vabs(b->exponent);
+    mx++; /* NOTE: An additional digit is needed for the compatibility to
+                   the version 1.2.1 and the former.  */
+    mx = (mx + 1) * VpBaseFig();
     GUARD_OBJ((*c), VpCreateRbObject(mx, "#0"));
     GUARD_OBJ((*res), VpCreateRbObject((mx+1) * 2 +(VpBaseFig() + 1), "#0"));
     VpDivd(*c, *res, a, b);
Index: ext/bigdecimal/bigdecimal.gemspec
===================================================================
--- ext/bigdecimal/bigdecimal.gemspec	(revision 44587)
+++ ext/bigdecimal/bigdecimal.gemspec	(revision 44588)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.gemspec#L1
 # -*- ruby -*-
-_VERSION = "1.2.3"
+_VERSION = "1.2.4"
 date = %w$Date::                           $[1]
 
 Gem::Specification.new do |s|
Index: test/bigdecimal/test_bigdecimal.rb
===================================================================
--- test/bigdecimal/test_bigdecimal.rb	(revision 44587)
+++ test/bigdecimal/test_bigdecimal.rb	(revision 44588)
@@ -701,6 +701,10 @@ class TestBigDecimal < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L701
     assert_equal(BigDecimal::SIGN_NEGATIVE_ZERO, (BigDecimal.new("-0") / 1).sign)
     assert_equal(2, BigDecimal.new("2") / 1)
     assert_equal(-2, BigDecimal.new("2") / -1)
+
+    assert_equal(BigDecimal('1486.868686869'), BigDecimal('1472.0') / BigDecimal('0.99'), '[ruby-core:59365] [#9316]')
+
+    assert_equal(4.124045235, BigDecimal('0.9932') / (700 * BigDecimal('0.344045') / BigDecimal('1000.0')), '[#9305]')
   end
 
   def test_div_with_float

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

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