Skip to content

Commit 5391f7e

Browse files
committed
Make VPrint function always available
1 parent 14f3d96 commit 5391f7e

File tree

1 file changed

+86
-91
lines changed

1 file changed

+86
-91
lines changed

ext/bigdecimal/bigdecimal.c

Lines changed: 86 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
*/
88

99
/* #define BIGDECIMAL_DEBUG 1 */
10-
#ifdef BIGDECIMAL_DEBUG
11-
# define BIGDECIMAL_ENABLE_VPRINT 1
12-
#endif
10+
1311
#include "bigdecimal.h"
1412
#include "ruby/util.h"
1513

@@ -198,10 +196,7 @@ static VALUE VpCheckGetValue(Real *p);
198196
static void VpInternalRound(Real *c, size_t ixDigit, DECDIG vPrev, DECDIG v);
199197
static int VpLimitRound(Real *c, size_t ixDigit);
200198
static Real *VpCopy(Real *pv, Real const* const x);
201-
202-
#ifdef BIGDECIMAL_ENABLE_VPRINT
203199
static int VPrint(FILE *fp,const char *cntl_chr,Real *a);
204-
#endif
205200

206201
/*
207202
* **** BigDecimal part ****
@@ -4501,6 +4496,8 @@ Init_bigdecimal(void)
45014496
id_to_r = rb_intern_const("to_r");
45024497
id_eq = rb_intern_const("==");
45034498
id_half = rb_intern_const("half");
4499+
4500+
(void)VPrint; /* suppress unused warning */
45044501
}
45054502

45064503
/*
@@ -6272,7 +6269,6 @@ VpComp(Real *a, Real *b)
62726269
* Note: % must not appear more than once
62736270
* a ... VP variable to be printed
62746271
*/
6275-
#ifdef BIGDECIMAL_ENABLE_VPRINT
62766272
static int
62776273
VPrint(FILE *fp, const char *cntl_chr, Real *a)
62786274
{
@@ -6285,95 +6281,94 @@ VPrint(FILE *fp, const char *cntl_chr, Real *a)
62856281
/* nc : number of characters printed */
62866282
ZeroSup = 1; /* Flag not to print the leading zeros as 0.00xxxxEnn */
62876283
while (*(cntl_chr + j)) {
6288-
if (*(cntl_chr + j) == '%' && *(cntl_chr + j + 1) != '%') {
6289-
nc = 0;
6290-
if (VpIsNaN(a)) {
6291-
fprintf(fp, SZ_NaN);
6292-
nc += 8;
6293-
}
6294-
else if (VpIsPosInf(a)) {
6295-
fprintf(fp, SZ_INF);
6296-
nc += 8;
6297-
}
6298-
else if (VpIsNegInf(a)) {
6299-
fprintf(fp, SZ_NINF);
6300-
nc += 9;
6301-
}
6302-
else if (!VpIsZero(a)) {
6303-
if (BIGDECIMAL_NEGATIVE_P(a)) {
6304-
fprintf(fp, "-");
6305-
++nc;
6306-
}
6307-
nc += fprintf(fp, "0.");
6308-
switch (*(cntl_chr + j + 1)) {
6309-
default:
6310-
break;
6284+
if (*(cntl_chr + j) == '%' && *(cntl_chr + j + 1) != '%') {
6285+
nc = 0;
6286+
if (VpIsNaN(a)) {
6287+
fprintf(fp, SZ_NaN);
6288+
nc += 8;
6289+
}
6290+
else if (VpIsPosInf(a)) {
6291+
fprintf(fp, SZ_INF);
6292+
nc += 8;
6293+
}
6294+
else if (VpIsNegInf(a)) {
6295+
fprintf(fp, SZ_NINF);
6296+
nc += 9;
6297+
}
6298+
else if (!VpIsZero(a)) {
6299+
if (BIGDECIMAL_NEGATIVE_P(a)) {
6300+
fprintf(fp, "-");
6301+
++nc;
6302+
}
6303+
nc += fprintf(fp, "0.");
6304+
switch (*(cntl_chr + j + 1)) {
6305+
default:
6306+
break;
63116307

6312-
case '0': case 'z':
6313-
ZeroSup = 0;
6314-
++j;
6315-
sep = cntl_chr[j] == 'z' ? BIGDECIMAL_COMPONENT_FIGURES : 10;
6316-
break;
6317-
}
6318-
for (i = 0; i < a->Prec; ++i) {
6319-
m = BASE1;
6320-
e = a->frac[i];
6321-
while (m) {
6322-
nn = e / m;
6323-
if (!ZeroSup || nn) {
6324-
nc += fprintf(fp, "%lu", (unsigned long)nn); /* The leading zero(s) */
6325-
/* as 0.00xx will not */
6326-
/* be printed. */
6327-
++nd;
6328-
ZeroSup = 0; /* Set to print succeeding zeros */
6329-
}
6330-
if (nd >= sep) { /* print ' ' after every 10 digits */
6331-
nd = 0;
6332-
nc += fprintf(fp, " ");
6333-
}
6334-
e = e - nn * m;
6335-
m /= 10;
6336-
}
6337-
}
6338-
nc += fprintf(fp, "E%"PRIdSIZE, VpExponent10(a));
6339-
nc += fprintf(fp, " (%"PRIdVALUE", %lu, %lu)", a->exponent, a->Prec, a->MaxPrec);
6340-
}
6341-
else {
6342-
nc += fprintf(fp, "0.0");
6343-
}
6344-
}
6345-
else {
6346-
++nc;
6347-
if (*(cntl_chr + j) == '\\') {
6348-
switch (*(cntl_chr + j + 1)) {
6349-
case 'n':
6350-
fprintf(fp, "\n");
6351-
++j;
6352-
break;
6353-
case 't':
6354-
fprintf(fp, "\t");
6355-
++j;
6356-
break;
6357-
case 'b':
6358-
fprintf(fp, "\n");
6359-
++j;
6360-
break;
6361-
default:
6362-
fprintf(fp, "%c", *(cntl_chr + j));
6363-
break;
6364-
}
6365-
}
6366-
else {
6367-
fprintf(fp, "%c", *(cntl_chr + j));
6368-
if (*(cntl_chr + j) == '%') ++j;
6369-
}
6370-
}
6371-
j++;
6308+
case '0': case 'z':
6309+
ZeroSup = 0;
6310+
++j;
6311+
sep = cntl_chr[j] == 'z' ? BIGDECIMAL_COMPONENT_FIGURES : 10;
6312+
break;
6313+
}
6314+
for (i = 0; i < a->Prec; ++i) {
6315+
m = BASE1;
6316+
e = a->frac[i];
6317+
while (m) {
6318+
nn = e / m;
6319+
if (!ZeroSup || nn) {
6320+
nc += fprintf(fp, "%lu", (unsigned long)nn); /* The leading zero(s) */
6321+
/* as 0.00xx will not */
6322+
/* be printed. */
6323+
++nd;
6324+
ZeroSup = 0; /* Set to print succeeding zeros */
6325+
}
6326+
if (nd >= sep) { /* print ' ' after every 10 digits */
6327+
nd = 0;
6328+
nc += fprintf(fp, " ");
6329+
}
6330+
e = e - nn * m;
6331+
m /= 10;
6332+
}
6333+
}
6334+
nc += fprintf(fp, "E%"PRIdSIZE, VpExponent10(a));
6335+
nc += fprintf(fp, " (%"PRIdVALUE", %lu, %lu)", a->exponent, a->Prec, a->MaxPrec);
6336+
}
6337+
else {
6338+
nc += fprintf(fp, "0.0");
6339+
}
6340+
}
6341+
else {
6342+
++nc;
6343+
if (*(cntl_chr + j) == '\\') {
6344+
switch (*(cntl_chr + j + 1)) {
6345+
case 'n':
6346+
fprintf(fp, "\n");
6347+
++j;
6348+
break;
6349+
case 't':
6350+
fprintf(fp, "\t");
6351+
++j;
6352+
break;
6353+
case 'b':
6354+
fprintf(fp, "\n");
6355+
++j;
6356+
break;
6357+
default:
6358+
fprintf(fp, "%c", *(cntl_chr + j));
6359+
break;
6360+
}
6361+
}
6362+
else {
6363+
fprintf(fp, "%c", *(cntl_chr + j));
6364+
if (*(cntl_chr + j) == '%') ++j;
6365+
}
6366+
}
6367+
j++;
63726368
}
63736369

63746370
return (int)nc;
63756371
}
6376-
#endif
63776372

63786373
static void
63796374
VpFormatSt(char *psz, size_t fFmt)

0 commit comments

Comments
 (0)