Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: return status of the 'let' builtin



On Mon 6 Apr 2026, at 17:51, Philippe Altherr wrote:
> It always bugged me that "typeset -p" doesn't use the proper
> capitalization. I hope that we can fix it.

apparently there is a standards aspect to this, discussed in 42407 and
42408. basically posix and iso c say that the %f/%g printf format
specifiers should use lower-case for nan/inf. the bit i referred to in
42369 was about making our printf consistently use those exact forms.
which it does, and i guess it should?

as for `typeset -p`, it uses convfloat() just like arithmetic constructs
do, but those values are handled differently depending on whether the
function is given a fd to write to (which it is for typeset but not for
arithmetic expansion). i don't understand why that should affect it

assuming we do in fact like NaN/Inf for non-printf use, this patch makes
the two cases work the same (extra context included so you can see what
i mean). please lmk if we *don't* like that

(obv if this goes in i will adjust the documentation examples)

dana


diff --git a/Src/params.c b/Src/params.c
index 461e02acf..001d89788 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -5746,19 +5746,24 @@ convfloat(double dval, int digits, int flags, FILE *fout)
 	     */
 	    digits--;
 	}
     }
 #ifdef USE_LOCALE
     prev_locale = dupstring(setlocale(LC_NUMERIC, NULL));
     setlocale(LC_NUMERIC, "POSIX");
 #endif
     if (fout) {
-	fprintf(fout, fmt, digits, dval);
+	if (isinf(dval))
+	    fprintf(fout, (dval < 0.0) ? "-Inf" : "Inf");
+	else if (isnan(dval))
+	    fprintf(fout, "NaN");
+	else
+	    fprintf(fout, fmt, digits, dval);
 	ret = NULL;
     } else {
 	VARARR(char, buf, 512 + digits);
 	if (isinf(dval))
 	    ret = dupstring((dval < 0.0) ? "-Inf" : "Inf");
 	else if (isnan(dval))
 	    ret = dupstring("NaN");
 	else {
 	    sprintf(buf, fmt, digits, dval);

diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index 7cca2bd81..8839e3891 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -1177,3 +1177,12 @@ F:This is a bug, the non -h variable should not hide the autoload variable
 >z=SRANDOM (zsh/random)
 >z=
 >v=
+
+ () {
+   typeset -F f1=nan f2=inf f3=-inf
+   typeset -p f1 f2 f3
+ }
+0:float NaN/Inf output formatting
+>typeset -F f1=NaN
+>typeset -F f2=Inf
+>typeset -F f3=-Inf




Messages sorted by: Reverse Date, Date, Thread, Author