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

ruby-changes:44262

From: nobu <ko1@a...>
Date: Tue, 4 Oct 2016 09:55:23 +0900 (JST)
Subject: [ruby-changes:44262] nobu:r56335 (trunk): bigdecimal.c: fix debug print

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

  New Revision: 56335

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

  Log:
    bigdecimal.c: fix debug print
    
    * ext/bigdecimal/bigdecimal.c (VpFree, VpInit): fix debug print
      format.
    
    * ext/bigdecimal/bigdecimal.c (VPrint): fix argument description,
      and embed NaN, Infinity, and zero in the format.

  Modified files:
    trunk/ext/bigdecimal/bigdecimal.c
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 56334)
+++ ext/bigdecimal/bigdecimal.c	(revision 56335)
@@ -3423,12 +3423,12 @@ VpFree(Real *pv) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L3423
 #ifdef BIGDECIMAL_DEBUG
 	gnAlloc--; /* Decrement allocation count */
 	if (gnAlloc == 0) {
-	    printf(" *************** All memories allocated freed ****************");
-	    getchar();
+	    printf(" *************** All memories allocated freed ****************\n");
+	    /*getchar();*/
 	}
 	if (gnAlloc <  0) {
 	    printf(" ??????????? Too many memory free calls(%d) ?????????????\n", gnAlloc);
-	    getchar();
+	    /*getchar();*/
 	}
 #endif /* BIGDECIMAL_DEBUG */
     }
@@ -3824,11 +3824,11 @@ VpInit(BDIGIT BaseVal) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L3824
 #ifdef BIGDECIMAL_DEBUG
     if (gfDebug) {
 	printf("VpInit: BaseVal   = %"PRIuBDIGIT"\n", BaseVal);
-	printf("  BASE   = %"PRIuBDIGIT"\n", BASE);
-	printf("  HALF_BASE = %"PRIuBDIGIT"\n", HALF_BASE);
-	printf("  BASE1  = %"PRIuBDIGIT"\n", BASE1);
-	printf("  BASE_FIG  = %u\n", BASE_FIG);
-	printf("  DBLE_FIG  = %d\n", DBLE_FIG);
+	printf("\tBASE      = %"PRIuBDIGIT"\n", BASE);
+	printf("\tHALF_BASE = %"PRIuBDIGIT"\n", HALF_BASE);
+	printf("\tBASE1     = %"PRIuBDIGIT"\n", BASE1);
+	printf("\tBASE_FIG  = %u\n", BASE_FIG);
+	printf("\tDBLE_FIG  = %d\n", DBLE_FIG);
     }
 #endif /* BIGDECIMAL_DEBUG */
 
@@ -5023,7 +5023,7 @@ Exit: https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L5023
  *      %  ... VP variable. To print '%', use '%%'.
  *      \n ... new line
  *      \b ... backspace
- *           ... tab
+ *      \t ... tab
  *     Note: % must not appear more than once
  *    a  ... VP variable to be printed
  */
@@ -5034,24 +5034,6 @@ VPrint(FILE *fp, const char *cntl_chr, R https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L5034
     size_t i, j, nc, nd, ZeroSup, sep = 10;
     BDIGIT m, e, nn;
 
-    /* Check if NaN & Inf. */
-    if (VpIsNaN(a)) {
-	fprintf(fp, SZ_NaN);
-	return 8;
-    }
-    if (VpIsPosInf(a)) {
-	fprintf(fp, SZ_INF);
-	return 8;
-    }
-    if (VpIsNegInf(a)) {
-	fprintf(fp, SZ_NINF);
-	return 9;
-    }
-    if (VpIsZero(a)) {
-	fprintf(fp, "0.0");
-	return 3;
-    }
-
     j = 0;
     nd = nc = 0;        /*  nd : number of digits in fraction part(every 10 digits, */
     /*    nd<=10). */
@@ -5060,7 +5042,19 @@ VPrint(FILE *fp, const char *cntl_chr, R https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L5042
     while (*(cntl_chr + j)) {
 	if (*(cntl_chr + j) == '%' && *(cntl_chr + j + 1) != '%') {
 	    nc = 0;
-	    if (!VpIsZero(a)) {
+	    if (VpIsNaN(a)) {
+		fprintf(fp, SZ_NaN);
+		nc += 8;
+	    }
+	    else if (VpIsPosInf(a)) {
+		fprintf(fp, SZ_INF);
+		nc += 8;
+	    }
+	    else if (VpIsNegInf(a)) {
+		fprintf(fp, SZ_NINF);
+		nc += 9;
+	    }
+	    else if (!VpIsZero(a)) {
 		if (VpGetSign(a) < 0) {
 		    fprintf(fp, "-");
 		    ++nc;

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

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