[ruby/bigdecimal] Make VPrint function always available
https://github.com/ruby/bigdecimal/commit/5391f7e92c
This commit is contained in:
parent
c0735d1d72
commit
019f53de5c
@ -7,9 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* #define BIGDECIMAL_DEBUG 1 */
|
/* #define BIGDECIMAL_DEBUG 1 */
|
||||||
#ifdef BIGDECIMAL_DEBUG
|
|
||||||
# define BIGDECIMAL_ENABLE_VPRINT 1
|
|
||||||
#endif
|
|
||||||
#include "bigdecimal.h"
|
#include "bigdecimal.h"
|
||||||
#include "ruby/util.h"
|
#include "ruby/util.h"
|
||||||
|
|
||||||
@ -198,10 +196,7 @@ static VALUE VpCheckGetValue(Real *p);
|
|||||||
static void VpInternalRound(Real *c, size_t ixDigit, DECDIG vPrev, DECDIG v);
|
static void VpInternalRound(Real *c, size_t ixDigit, DECDIG vPrev, DECDIG v);
|
||||||
static int VpLimitRound(Real *c, size_t ixDigit);
|
static int VpLimitRound(Real *c, size_t ixDigit);
|
||||||
static Real *VpCopy(Real *pv, Real const* const x);
|
static Real *VpCopy(Real *pv, Real const* const x);
|
||||||
|
|
||||||
#ifdef BIGDECIMAL_ENABLE_VPRINT
|
|
||||||
static int VPrint(FILE *fp,const char *cntl_chr,Real *a);
|
static int VPrint(FILE *fp,const char *cntl_chr,Real *a);
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* **** BigDecimal part ****
|
* **** BigDecimal part ****
|
||||||
@ -4501,6 +4496,8 @@ Init_bigdecimal(void)
|
|||||||
id_to_r = rb_intern_const("to_r");
|
id_to_r = rb_intern_const("to_r");
|
||||||
id_eq = rb_intern_const("==");
|
id_eq = rb_intern_const("==");
|
||||||
id_half = rb_intern_const("half");
|
id_half = rb_intern_const("half");
|
||||||
|
|
||||||
|
(void)VPrint; /* suppress unused warning */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -6272,7 +6269,6 @@ Exit:
|
|||||||
* 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
|
||||||
*/
|
*/
|
||||||
#ifdef BIGDECIMAL_ENABLE_VPRINT
|
|
||||||
static int
|
static int
|
||||||
VPrint(FILE *fp, const char *cntl_chr, Real *a)
|
VPrint(FILE *fp, const char *cntl_chr, Real *a)
|
||||||
{
|
{
|
||||||
@ -6285,95 +6281,94 @@ VPrint(FILE *fp, const char *cntl_chr, Real *a)
|
|||||||
/* nc : number of characters printed */
|
/* nc : number of characters printed */
|
||||||
ZeroSup = 1; /* Flag not to print the leading zeros as 0.00xxxxEnn */
|
ZeroSup = 1; /* Flag not to print the leading zeros as 0.00xxxxEnn */
|
||||||
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 (VpIsNaN(a)) {
|
if (VpIsNaN(a)) {
|
||||||
fprintf(fp, SZ_NaN);
|
fprintf(fp, SZ_NaN);
|
||||||
nc += 8;
|
nc += 8;
|
||||||
}
|
}
|
||||||
else if (VpIsPosInf(a)) {
|
else if (VpIsPosInf(a)) {
|
||||||
fprintf(fp, SZ_INF);
|
fprintf(fp, SZ_INF);
|
||||||
nc += 8;
|
nc += 8;
|
||||||
}
|
}
|
||||||
else if (VpIsNegInf(a)) {
|
else if (VpIsNegInf(a)) {
|
||||||
fprintf(fp, SZ_NINF);
|
fprintf(fp, SZ_NINF);
|
||||||
nc += 9;
|
nc += 9;
|
||||||
}
|
}
|
||||||
else if (!VpIsZero(a)) {
|
else if (!VpIsZero(a)) {
|
||||||
if (BIGDECIMAL_NEGATIVE_P(a)) {
|
if (BIGDECIMAL_NEGATIVE_P(a)) {
|
||||||
fprintf(fp, "-");
|
fprintf(fp, "-");
|
||||||
++nc;
|
++nc;
|
||||||
}
|
}
|
||||||
nc += fprintf(fp, "0.");
|
nc += fprintf(fp, "0.");
|
||||||
switch (*(cntl_chr + j + 1)) {
|
switch (*(cntl_chr + j + 1)) {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '0': case 'z':
|
case '0': case 'z':
|
||||||
ZeroSup = 0;
|
ZeroSup = 0;
|
||||||
++j;
|
++j;
|
||||||
sep = cntl_chr[j] == 'z' ? BIGDECIMAL_COMPONENT_FIGURES : 10;
|
sep = cntl_chr[j] == 'z' ? BIGDECIMAL_COMPONENT_FIGURES : 10;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (i = 0; i < a->Prec; ++i) {
|
for (i = 0; i < a->Prec; ++i) {
|
||||||
m = BASE1;
|
m = BASE1;
|
||||||
e = a->frac[i];
|
e = a->frac[i];
|
||||||
while (m) {
|
while (m) {
|
||||||
nn = e / m;
|
nn = e / m;
|
||||||
if (!ZeroSup || nn) {
|
if (!ZeroSup || nn) {
|
||||||
nc += fprintf(fp, "%lu", (unsigned long)nn); /* The leading zero(s) */
|
nc += fprintf(fp, "%lu", (unsigned long)nn); /* The leading zero(s) */
|
||||||
/* as 0.00xx will not */
|
/* as 0.00xx will not */
|
||||||
/* be printed. */
|
/* be printed. */
|
||||||
++nd;
|
++nd;
|
||||||
ZeroSup = 0; /* Set to print succeeding zeros */
|
ZeroSup = 0; /* Set to print succeeding zeros */
|
||||||
}
|
}
|
||||||
if (nd >= sep) { /* print ' ' after every 10 digits */
|
if (nd >= sep) { /* print ' ' after every 10 digits */
|
||||||
nd = 0;
|
nd = 0;
|
||||||
nc += fprintf(fp, " ");
|
nc += fprintf(fp, " ");
|
||||||
}
|
}
|
||||||
e = e - nn * m;
|
e = e - nn * m;
|
||||||
m /= 10;
|
m /= 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nc += fprintf(fp, "E%"PRIdSIZE, VpExponent10(a));
|
nc += fprintf(fp, "E%"PRIdSIZE, VpExponent10(a));
|
||||||
nc += fprintf(fp, " (%"PRIdVALUE", %lu, %lu)", a->exponent, a->Prec, a->MaxPrec);
|
nc += fprintf(fp, " (%"PRIdVALUE", %lu, %lu)", a->exponent, a->Prec, a->MaxPrec);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
nc += fprintf(fp, "0.0");
|
nc += fprintf(fp, "0.0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
++nc;
|
++nc;
|
||||||
if (*(cntl_chr + j) == '\\') {
|
if (*(cntl_chr + j) == '\\') {
|
||||||
switch (*(cntl_chr + j + 1)) {
|
switch (*(cntl_chr + j + 1)) {
|
||||||
case 'n':
|
case 'n':
|
||||||
fprintf(fp, "\n");
|
fprintf(fp, "\n");
|
||||||
++j;
|
++j;
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
fprintf(fp, "\t");
|
fprintf(fp, "\t");
|
||||||
++j;
|
++j;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
fprintf(fp, "\n");
|
fprintf(fp, "\n");
|
||||||
++j;
|
++j;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(fp, "%c", *(cntl_chr + j));
|
fprintf(fp, "%c", *(cntl_chr + j));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(fp, "%c", *(cntl_chr + j));
|
fprintf(fp, "%c", *(cntl_chr + j));
|
||||||
if (*(cntl_chr + j) == '%') ++j;
|
if (*(cntl_chr + j) == '%') ++j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)nc;
|
return (int)nc;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
VpFormatSt(char *psz, size_t fFmt)
|
VpFormatSt(char *psz, size_t fFmt)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user