[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[SCM] gawk branch, stable/printf-rework, updated. gawk-4.1.0-5502-g8f14d
From: |
Arnold Robbins |
Subject: |
[SCM] gawk branch, stable/printf-rework, updated. gawk-4.1.0-5502-g8f14d054 |
Date: |
Thu, 11 Jul 2024 11:13:31 -0400 (EDT) |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".
The branch, stable/printf-rework has been updated
via 8f14d054736a4d1b5daee636dbfebac923ba7fdf (commit)
from 61a8624fdf8827582b00d962f6d6a8ad5a5f5264 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=8f14d054736a4d1b5daee636dbfebac923ba7fdf
commit 8f14d054736a4d1b5daee636dbfebac923ba7fdf
Author: Arnold D. Robbins <arnold@skeeve.com>
Date: Thu Jul 11 18:13:10 2024 +0300
Continuing on printf, good progress.
diff --git a/ChangeLog b/ChangeLog
index bdb6153a..105ab551 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,8 @@
2024-07-11 Arnold D. Robbins <arnold@skeeve.com>
* printf.c: Signed and unsigned integer printing and float printing
- working for current tests.
+ working for current tests. MPFR integer printing also for current
+ tests. A few tests still to go in printf-corners.
2024-07-09 Arnold D. Robbins <arnold@skeeve.com>
diff --git a/printf.c b/printf.c
index 96a4f84c..d8a4dba2 100644
--- a/printf.c
+++ b/printf.c
@@ -2395,9 +2395,9 @@ format_integer_digits(NODE *arg, struct flags *flags)
buflen = VALUE_SIZE;
cp = buf;
+ tmpval = double_to_int(arg->numbr);
if (flags->base == 10 && flags->format != 'u') {
// signed decimal
- tmpval = double_to_int(arg->numbr);
if (tmpval == -0)
tmpval = 0;
@@ -2417,7 +2417,21 @@ format_integer_digits(NODE *arg, struct flags *flags)
// octal or hex
chbuf = (flags->format == 'X' ? Uchbuf : lchbuf);
- uval = get_number_uj(arg);
+ if (tmpval < 0) {
+ uval = (uintmax_t) (intmax_t) tmpval;
+ if ((AWKNUM)(intmax_t)uval != double_to_int(tmpval)) {
+ flags->format = 'g';
+ free((void *) buf);
+ return format_float(arg, flags);
+ }
+ } else {
+ uval = (uintmax_t) tmpval;
+ if ((AWKNUM)uval != double_to_int(tmpval)) {
+ flags->format = 'g';
+ free((void *) buf);
+ return format_float(arg, flags);
+ }
+ }
// generate the digits backwards.
do {
@@ -2794,7 +2808,8 @@ format_out_of_range(NODE *arg, struct flags *flags)
if (flags->left_just) {
strcpy(cp, nan_inf_val);
cp += len;
- for (cp = buf; fw > len; fw--)
+ fw -= len;
+ for (; fw > 0; fw--)
*cp++ = ' ';
*cp = '\0';
} else {
@@ -2836,12 +2851,21 @@ compute_zero_flag(struct flags *flags)
static const char *
format_mpg_integer(NODE *arg, struct flags *flags)
{
-#if 0
#ifdef HAVE_MPFR
+#undef cpbuf
mpz_ptr zi;
mpfr_ptr mf;
- bool zero_flags = compute_zero_flag(flags);
+ enum { MP_NONE = 0, MP_INT_WITH_PREC = 1, MP_INT_WITHOUT_PREC }
fmt_type;
+ char *buf;
+ size_t buflen;
+ double tmpval;
+ uintmax_t uval;
+ char *cp;
+ char cpbuf[30];
+ int nc;
+ bool need_to_add_thousands = false;
+ fmt_type = flags->have_prec ? MP_INT_WITH_PREC : MP_INT_WITHOUT_PREC;
if (is_mpg_integer(arg)) {
zi = arg->mpg_i;
@@ -2856,22 +2880,18 @@ format_mpg_integer(NODE *arg, struct flags *flags)
mf = mpz2mpfr(zi);
goto mpf1;
}
- signchar = '\0'; /* Don't print '+' */
}
- zero_flags = compute_zero_flag(flags);
-
- fmt_type = have_prec ? MP_INT_WITH_PREC : MP_INT_WITHOUT_PREC;
+// fmt_type = flags->have_prec ? MP_INT_WITH_PREC :
MP_INT_WITHOUT_PREC;
goto fmt0;
} else if (is_mpg_float(arg)) {
-mpf0:
mf = arg->mpg_numbr;
if (! mpfr_number_p(mf)) {
cant_happen("%s", "format_mpg_integer called on nan or
inf");
}
- if (cs1 != 'd' && cs1 != 'i') {
+ if (flags->format != 'd' && flags->format != 'i') {
mpf1:
/*
* The output of printf("%#.0x", 0) is 0 instead of 0x,
hence <= in
@@ -2883,31 +2903,88 @@ mpf1:
}
tmpval = uval = (uintmax_t) mpfr_get_sj(mf,
ROUND_MODE);
- if (! alt && have_prec && prec == 0 && tmpval
== 0) {
+ if (! flags->alt && flags->have_prec &&
flags->precision == 0 && tmpval == 0) {
if (flags->base == 8)
return strdup("0");
else
return strdup(""); /*
printf("%.0x", 0) is no characters */
}
- goto int0;
+ goto fmt0;
}
}
- /* See comments above about when to fill with zeros */
- zero_flag = (! lj
- && ((zero_flag && ! have_prec)
- || (fw == 0 && have_prec)));
-
(void) mpfr_get_z(mpzval, mf, MPFR_RNDZ); /* convert to
GMP integer */
- fmt_type = have_prec ? MP_INT_WITH_PREC : MP_INT_WITHOUT_PREC;
+// fmt_type = flags->have_prec ? MP_INT_WITH_PREC :
MP_INT_WITHOUT_PREC;
zi = mpzval;
- goto fmt0;
+ // fall through
}
-#else
- cant_happen("%s", "trying to format GMP integer");
+fmt0:
+ buflen = flags->field_width + flags->precision + 11; /* 11 == slop */
+ emalloc(buf, char *, buflen, "format_mpg_integer");
+
+ int signchar = '\0';
+ if (flags->plus)
+ signchar = '+';
+ else if (flags->space)
+ signchar = ' ';
+
+ cp = cpbuf;
+ *cp++ = '%';
+ if (flags->left_just)
+ *cp++ = '-';
+ if (signchar)
+ *cp++ = signchar;
+ if (flags->alt)
+ *cp++ = '#';
+ if (flags->zero)
+ *cp++ = '0';
+ if (flags->quote)
+ *cp++ = '\'';
+
+#if defined(LC_NUMERIC)
+ if (flags->quote && ! use_lc_numeric)
+ setlocale(LC_NUMERIC, "");
+#endif
+
+ switch (fmt_type) {
+ case MP_INT_WITH_PREC:
+ sprintf(cp, "*.*Z%c", flags->format);
+ while ((nc = mpfr_snprintf(buf, buflen, cpbuf,
+ flags->field_width, flags->precision, zi)) >=
(int) buflen) {
+ buflen *= 2;
+ erealloc(buf, char *, buflen, "format_mpg_integer");
+ }
+ need_to_add_thousands = true;
+ break;
+ case MP_INT_WITHOUT_PREC:
+ sprintf(cp, "*Z%c", flags->format);
+ while ((nc = mpfr_snprintf(buf, buflen, cpbuf,
+ flags->field_width, zi)) >= (int) buflen) {
+ buflen *= 2;
+ erealloc(buf, char *, buflen, "format_mpg_integer");
+ }
+ need_to_add_thousands = true;
+ break;
+ default:
+ cant_happen("unknown MP_INT formatting type: %d", fmt_type);
+ break;
+ }
+
+#if defined(LC_NUMERIC)
+ if (flags->quote && ! use_lc_numeric)
+ setlocale(LC_NUMERIC, "C");
#endif
+
+ if (flags->quote && flags->base == 10 && need_to_add_thousands) {
+ const char *new_text = add_thousands(buf);
+
+ free((void *) buf);
+ buf = (char *) new_text;
+ }
+
+ return buf;
#else
- return strdup("mpgint");
+ cant_happen("%s", "trying to format GMP integer");
#endif
}
@@ -2979,9 +3056,6 @@ adjust_flags(struct flags *flags)
flags->space = false;
}
- if (flags->left_just)
- flags->zero = false;
-
if (strchr("diouxX", flags->format) != NULL && flags->have_prec)
flags->zero = false;
}
@@ -2999,7 +3073,7 @@ format_float(NODE *arg, struct flags *flags)
double tmpval;
#ifdef HAVE_MPFR
- mpfr_ptr mf;
+ mpfr_ptr mf = NULL;
#endif
bool quote_flag = false;
int nc;
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 3 +-
printf.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++-------------
2 files changed, 103 insertions(+), 28 deletions(-)
hooks/post-receive
--
gawk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [SCM] gawk branch, stable/printf-rework, updated. gawk-4.1.0-5502-g8f14d054,
Arnold Robbins <=