Date: Sun, 27 Sep 1998 12:39:19 +0300 (IDT) From: Eli Zaretskii To: DJ Delorie cc: djgpp-workers AT delorie DOT com Subject: Re: snapshot 980907 In-Reply-To: <199809080049.UAA11536@delorie.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk Here's a patch that makes "%+f" always print the correct sign, even if the number comes out as all-zeros. A related problem (which this patch does not solve) is that "%+f" prints "+NaN", even if the bit pattern of NaN has its sign bit set, like if you print the value of -nanf(). `doprnt.c' explicitly says that "-NaN" is ``not nice''. While I can understand the argument that a NaN should be printed without a sign, I think "%+f" should then print just "NaN", with no sign at all. If people agree, I will submit a patch for that as well. *** src/libc/ansi/stdio/doprnt.c~0 Sun Jul 12 15:30:42 1998 --- src/libc/ansi/stdio/doprnt.c Fri Sep 25 18:15:28 1998 *************** _doprnt(const char *fmt0, va_list argp, *** 96,101 **** --- 96,102 ---- char softsign; /* temporary negative sign for floats */ const char *digs; /* digits for [diouxX] conversion */ char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */ + int neg_ldouble = 0; /* non-zero if _ldouble is negative */ decimal = localeconv()->decimal_point[0]; *************** _doprnt(const char *fmt0, va_list argp, *** 247,255 **** --- 248,260 ---- { softsign = '-'; _ldouble = -_ldouble; + neg_ldouble = 1; } else + { softsign = 0; + neg_ldouble = 0; + } /* * cvt may have to round up past the "start" of the * buffer, i.e. ``intf("%.2f", (double)9.999);''; *************** _doprnt(const char *fmt0, va_list argp, *** 258,264 **** *buf = NULL; size = cvtl(_ldouble, prec, flags, &softsign, *fmt, buf, buf + sizeof(buf)); ! if (softsign && !nan) sign = '-'; nan = 0; t = *buf ? buf : buf + 1; --- 263,274 ---- *buf = NULL; size = cvtl(_ldouble, prec, flags, &softsign, *fmt, buf, buf + sizeof(buf)); ! /* ! * If the format specifier requested an explicit sign, ! * we print a negative sign even if no significant digits ! * will be shown. In other words, "%+f" might yield -0.000000. ! */ ! if (!nan && (softsign || (sign == '+' && neg_ldouble))) sign = '-'; nan = 0; t = *buf ? buf : buf + 1;