gawk-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] gawk branch, stable/printf-rework, updated. gawk-4.1.0-5509-g057d4


From: Arnold Robbins
Subject: [SCM] gawk branch, stable/printf-rework, updated. gawk-4.1.0-5509-g057d4307
Date: Mon, 15 Jul 2024 23:18:08 -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  057d4307ed06d0247c8756e1d18312f37e22fe90 (commit)
      from  3575846a3d015fa7132a398e5c4779d6e623f2d6 (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=057d4307ed06d0247c8756e1d18312f37e22fe90

commit 057d4307ed06d0247c8756e1d18312f37e22fe90
Author: Arnold D. Robbins <arnold@skeeve.com>
Date:   Tue Jul 16 06:17:49 2024 +0300

    Passing tests. Cleanup still needed.

diff --git a/ChangeLog b/ChangeLog
index a4470554..63863a53 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-07-16         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * printf.c: Use mpfr_sprintf() just to generate digits.
+       All tests now passing, even with -M.
+
 2024-07-13         Arnold D. Robbins     <arnold@skeeve.com>
 
        * printf.c: Continued progress against the printf-corners test.
diff --git a/printf.c b/printf.c
index 8f189898..be58a500 100644
--- a/printf.c
+++ b/printf.c
@@ -54,9 +54,10 @@ static void reverse(char *str);
 static bool compute_zero_flag(struct flags *flags);
 static void adjust_flags(struct flags *flags);
 static const char *add_thousands(const char *original);
+static const char *format_integer_digits(NODE *arg, struct flags *flags);
+static const char *format_mpg_integer_digits(NODE *arg, struct flags *flags, 
bool *used_float);
 static const char *format_signed_integer(NODE *arg, struct flags *flags);
 static const char *format_unsigned_integer(NODE *arg, struct flags *flags);
-static const char *format_mpg_integer(NODE *arg, struct flags *flags);
 static const char *format_float(NODE *arg, struct flags *flags);
 static const char *format_out_of_range(NODE *arg, struct flags *flags);
 
@@ -2472,14 +2473,19 @@ format_signed_integer(NODE *arg, struct flags *flags)
        size_t val_len;
        char *buf1 = NULL;
        char fill[] = " ";
+       bool used_float = false;
 
        if (out_of_range(arg))
                return format_out_of_range(arg, flags);
 
        if (is_mpg_integer(arg) || is_mpg_float(arg))
-               return format_mpg_integer(arg, flags);
+               number_value = format_mpg_integer_digits(arg, flags, & 
used_float);
+       else
+               number_value = format_integer_digits(arg, flags);       // just 
digits, possible leading '-'
+
+       if (used_float)
+               return number_value;
 
-       number_value = format_integer_digits(arg, flags);       // just digits, 
possible leading '-'
        val_len = strlen(number_value);
 
        // We now have the initial *integer* decimalvalue in hand.
@@ -2663,14 +2669,19 @@ format_unsigned_integer(NODE *arg, struct flags *flags)
        char *buf2 = NULL;
        char fill[] = " ";
        size_t val_len;
+       bool used_float = false;
 
        if (out_of_range(arg))
                return format_out_of_range(arg, flags);
 
        if (is_mpg_integer(arg) || is_mpg_float(arg))
-               return format_mpg_integer(arg, flags);
+               number_value = format_mpg_integer_digits(arg, flags, & 
used_float);
+       else
+               number_value = format_integer_digits(arg, flags);       // just 
digits
+
+       if (used_float)
+               return number_value;
 
-       number_value = format_integer_digits(arg, flags);       // just digits
        val_len = strlen(number_value);
 
        // We now have the initial *integer* decimal, octal, or hex value in 
hand.
@@ -2897,14 +2908,19 @@ compute_zero_flag(struct flags *flags)
 
 /* format_mpg_integer --- format an MPZ or MPFR integer. caller frees return 
value */
 
+/*
+ * It seems that mpfr_snprintf() doesn't exactly mimic snprintf() with respect
+ * to all the flags and width and precision.  So we instead we simply generate
+ * the digits and let the higher level code handle padding and so on.
+ */
+
 static const char *
-format_mpg_integer(NODE *arg, struct flags *flags)
+format_mpg_integer_digits(NODE *arg, struct flags *flags, bool *used_float)
 {
 #ifdef HAVE_MPFR
 #undef cpbuf
        mpz_ptr zi;
        mpfr_ptr mf;
-       enum { MP_NONE = 0, MP_INT_WITH_PREC = 1, MP_INT_WITHOUT_PREC } 
fmt_type;
        char *buf;
        size_t buflen;
        double tmpval;
@@ -2914,7 +2930,11 @@ format_mpg_integer(NODE *arg, struct flags *flags)
        int nc;
        bool need_to_add_thousands = (strchr("diu", flags->format) != NULL);
 
-       fmt_type = flags->have_prec ? MP_INT_WITH_PREC : MP_INT_WITHOUT_PREC;
+       *used_float = false;
+
+       if (is_zero(arg))
+               return estrdup("0", 1);
+
        if (is_mpg_integer(arg)) {
                zi = arg->mpg_i;
 
@@ -2929,11 +2949,8 @@ format_mpg_integer(NODE *arg, struct flags *flags)
                                mf = mpz2mpfr(zi);
                                goto mpf1;
                        }
-                       flags->plus = flags->space = false;     // Don't print 
the +
                }
 
-//             fmt_type = flags->have_prec ? MP_INT_WITH_PREC : 
MP_INT_WITHOUT_PREC;
-               goto fmt0;
 
        } else if (is_mpg_float(arg)) {
                mf = arg->mpg_numbr;
@@ -2949,23 +2966,14 @@ mpf1:
                         */
                        if (mpfr_sgn(mf) <= 0) {
                                if (! mpfr_fits_intmax_p(mf, ROUND_MODE)) {
+                                       *used_float = true;
                                        return format_float(arg, flags);
                                }
-
-                               tmpval = uval = (uintmax_t) mpfr_get_sj(mf, 
ROUND_MODE);
-                               if (! flags->alt && flags->have_prec && 
flags->precision == 0 && tmpval == 0) {
-                                       if (flags->base == 8)
-                                               return estrdup("0", 1);
-                                       else
-                                               return estrdup("", 1);  /* 
printf("%.0x", 0) is no characters */
-                               }
                                goto fmt0;
                        }
-                       flags->plus = flags->space = false;     // Don't print 
the +
                }
 
                (void) mpfr_get_z(mpzval, mf, MPFR_RNDZ);       /* convert to 
GMP integer */
-//             fmt_type = flags->have_prec ? MP_INT_WITH_PREC : 
MP_INT_WITHOUT_PREC;
                zi = mpzval;
                // fall through
        }
@@ -2973,53 +2981,16 @@ 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 = ' ';
-
-       bool zero_flag = compute_zero_flag(flags);
-       cp = cpbuf;
-       *cp++ = '%';
-       if (flags->left_just)
-               *cp++ = '-';
-       if (signchar)
-               *cp++ = signchar;
-       if (flags->alt)
-               *cp++ = '#';
-       if (zero_flag)
-               *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;
+       sprintf(cpbuf, "%%Z%c", flags->format);
+       while ((nc = mpfr_snprintf(buf, buflen, cpbuf, zi)) >= (int) buflen) {
+               buflen *= 2;
+               erealloc(buf, char *, buflen, "format_mpg_integer");
        }
 
 #if defined(LC_NUMERIC)

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog |  5 ++++
 printf.c  | 95 ++++++++++++++++++++++-----------------------------------------
 2 files changed, 38 insertions(+), 62 deletions(-)


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]