1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-10-04 00:55:14 +00:00
parent ee1acb555e
commit 1ae50df95d

View file

@ -3423,12 +3423,12 @@ VpFree(Real *pv)
#ifdef BIGDECIMAL_DEBUG #ifdef BIGDECIMAL_DEBUG
gnAlloc--; /* Decrement allocation count */ gnAlloc--; /* Decrement allocation count */
if (gnAlloc == 0) { if (gnAlloc == 0) {
printf(" *************** All memories allocated freed ****************"); printf(" *************** All memories allocated freed ****************\n");
getchar(); /*getchar();*/
} }
if (gnAlloc < 0) { if (gnAlloc < 0) {
printf(" ??????????? Too many memory free calls(%d) ?????????????\n", gnAlloc); printf(" ??????????? Too many memory free calls(%d) ?????????????\n", gnAlloc);
getchar(); /*getchar();*/
} }
#endif /* BIGDECIMAL_DEBUG */ #endif /* BIGDECIMAL_DEBUG */
} }
@ -3824,11 +3824,11 @@ VpInit(BDIGIT BaseVal)
#ifdef BIGDECIMAL_DEBUG #ifdef BIGDECIMAL_DEBUG
if (gfDebug) { if (gfDebug) {
printf("VpInit: BaseVal = %"PRIuBDIGIT"\n", BaseVal); printf("VpInit: BaseVal = %"PRIuBDIGIT"\n", BaseVal);
printf(" BASE = %"PRIuBDIGIT"\n", BASE); printf("\tBASE = %"PRIuBDIGIT"\n", BASE);
printf(" HALF_BASE = %"PRIuBDIGIT"\n", HALF_BASE); printf("\tHALF_BASE = %"PRIuBDIGIT"\n", HALF_BASE);
printf(" BASE1 = %"PRIuBDIGIT"\n", BASE1); printf("\tBASE1 = %"PRIuBDIGIT"\n", BASE1);
printf(" BASE_FIG = %u\n", BASE_FIG); printf("\tBASE_FIG = %u\n", BASE_FIG);
printf(" DBLE_FIG = %d\n", DBLE_FIG); printf("\tDBLE_FIG = %d\n", DBLE_FIG);
} }
#endif /* BIGDECIMAL_DEBUG */ #endif /* BIGDECIMAL_DEBUG */
@ -5023,7 +5023,7 @@ Exit:
* % ... VP variable. To print '%', use '%%'. * % ... VP variable. To print '%', use '%%'.
* \n ... new line * \n ... new line
* \b ... backspace * \b ... backspace
* ... tab * \t ... tab
* Note: % must not appear more than once * Note: % must not appear more than once
* a ... VP variable to be printed * a ... VP variable to be printed
*/ */
@ -5034,24 +5034,6 @@ VPrint(FILE *fp, const char *cntl_chr, Real *a)
size_t i, j, nc, nd, ZeroSup, sep = 10; size_t i, j, nc, nd, ZeroSup, sep = 10;
BDIGIT m, e, nn; 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; j = 0;
nd = nc = 0; /* nd : number of digits in fraction part(every 10 digits, */ nd = nc = 0; /* nd : number of digits in fraction part(every 10 digits, */
/* nd<=10). */ /* nd<=10). */
@ -5060,7 +5042,19 @@ VPrint(FILE *fp, const char *cntl_chr, Real *a)
while (*(cntl_chr + j)) { while (*(cntl_chr + j)) {
if (*(cntl_chr + j) == '%' && *(cntl_chr + j + 1) != '%') { if (*(cntl_chr + j) == '%' && *(cntl_chr + j + 1) != '%') {
nc = 0; 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) { if (VpGetSign(a) < 0) {
fprintf(fp, "-"); fprintf(fp, "-");
++nc; ++nc;