Drop support for MSVCRT's float formatting quirk.
authorThomas Munro <tmunro@postgresql.org>
Wed, 19 Nov 2025 21:23:44 +0000 (10:23 +1300)
committerThomas Munro <tmunro@postgresql.org>
Wed, 19 Nov 2025 21:38:15 +0000 (10:38 +1300)
Commit f1885386 added code to remove an unnecessary leading zero from
the exponent in a float formatted by the system snprintf().  The C
standard doesn't allow unnecessary digits beyond two, and the tests pass
without this on Windows' modern UCRT (required since commit 1758d424).

Discussion: https://postgr.es/m/CA%2BhUKGJnmzTqiODmTjf-23yZ%3DE3HXqFTtKoyp3TF-MpB93hTMQ%40mail.gmail.com

src/port/snprintf.c

index dded6c3f65bac54910d7892f2e17fabae6a05e6f..6541182df6d168473145cc9a2f5aadfac25723b5 100644 (file)
@@ -1205,22 +1205,6 @@ fmtfloat(double value, char type, int forcesign, int leftjust,
        }
        if (vallen < 0)
            goto fail;
-
-       /*
-        * Windows, alone among our supported platforms, likes to emit
-        * three-digit exponent fields even when two digits would do.  Hack
-        * such results to look like the way everyone else does it.
-        */
-#ifdef WIN32
-       if (vallen >= 6 &&
-           convert[vallen - 5] == 'e' &&
-           convert[vallen - 3] == '0')
-       {
-           convert[vallen - 3] = convert[vallen - 2];
-           convert[vallen - 2] = convert[vallen - 1];
-           vallen--;
-       }
-#endif
    }
 
    padlen = compute_padlen(minlen, vallen + zeropadlen, leftjust);
@@ -1336,17 +1320,6 @@ pg_strfromd(char *str, size_t count, int precision, double value)
                target.failed = true;
                goto fail;
            }
-
-#ifdef WIN32
-           if (vallen >= 6 &&
-               convert[vallen - 5] == 'e' &&
-               convert[vallen - 3] == '0')
-           {
-               convert[vallen - 3] = convert[vallen - 2];
-               convert[vallen - 2] = convert[vallen - 1];
-               vallen--;
-           }
-#endif
        }
    }