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

ruby-changes:14585

From: mame <ko1@a...>
Date: Tue, 26 Jan 2010 21:53:05 +0900 (JST)
Subject: [ruby-changes:14585] Ruby:r26428 (trunk): * ext/bigdecimal/bigdecimal.c (VpCtoV): BigDecimal("0E200000000000")

mame	2010-01-26 21:52:49 +0900 (Tue, 26 Jan 2010)

  New Revision: 26428

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

  Log:
    * ext/bigdecimal/bigdecimal.c (VpCtoV): BigDecimal("0E200000000000")
      was Infinity, not 0.
    
    * test/bigdecimal/test_bigdecimal.rb: add a test for above.

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/bigdecimal.c
    trunk/test/bigdecimal/test_bigdecimal.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26427)
+++ ChangeLog	(revision 26428)
@@ -1,3 +1,10 @@
+Tue Jan 26 21:50:31 2010  Yusuke Endoh  <mame@t...>
+
+	* ext/bigdecimal/bigdecimal.c (VpCtoV): BigDecimal("0E200000000000")
+	  was Infinity, not 0.
+
+	* test/bigdecimal/test_bigdecimal.rb: add a test for above.
+
 Tue Jan 26 21:36:22 2010  Tanaka Akira  <akr@f...>
 
 	* configure.in: test unsetenv returns a value.
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 26427)
+++ ext/bigdecimal/bigdecimal.c	(revision 26428)
@@ -4009,13 +4009,14 @@
     U_LONG i, j, ind_a, ma, mi, me;
     U_LONG loc;
     S_INT  e,es, eb, ef;
-    S_INT  sign, signe;
+    S_INT  sign, signe, exponent_overflow;
     /* get exponent part */
     e = 0;
     ma = a->MaxPrec;
     mi = ni;
     me = ne;
     signe = 1;
+    exponent_overflow = 0;
     memset(a->frac, 0, ma * sizeof(U_LONG));
     if(ne > 0) {
         i = 0;
@@ -4031,12 +4032,8 @@
             es = e*((S_INT)BASE_FIG);
             e = e * 10 + exp_chr[i] - '0';
             if(es>e*((S_INT)BASE_FIG)) {
-                VpException(VP_EXCEPTION_INFINITY,"exponent overflow",0);
-                sign = 1;
-                if(int_chr[0] == '-') sign = -1;
-                if(signe > 0) VpSetInf(a, sign);
-                else VpSetZero(a, sign);
-                return 1;
+		exponent_overflow = 1;
+		break;
             }
             ++i;
         }
@@ -4078,6 +4075,16 @@
 
     eb = e / ((S_INT)BASE_FIG);
 
+    if(exponent_overflow) {
+	int zero = 1;
+	for(     ; i < mi && zero; i++) zero = int_chr[i] == '0';
+	for(i = 0; i < nf && zero; i++) zero = frac[i] == '0';
+	if(!zero && signe > 0) VpSetInf(a, sign);
+	else VpSetZero(a, sign);
+        VpException(VP_EXCEPTION_INFINITY,"exponent overflow",0);
+	return 1;
+    }
+
     ind_a = 0;
     while(i < mi) {
         a->frac[ind_a] = 0;
Index: test/bigdecimal/test_bigdecimal.rb
===================================================================
--- test/bigdecimal/test_bigdecimal.rb	(revision 26427)
+++ test/bigdecimal/test_bigdecimal.rb	(revision 26428)
@@ -177,6 +177,7 @@
   def test_zero_p
     assert_equal(true, BigDecimal.new("0").zero?)
     assert_equal(false, BigDecimal.new("1").zero?)
+    assert_equal(true, BigDecimal.new("0E200000000000000").zero?)
   end
 
   def test_nonzero_p

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

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