delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/09/27/05:40:16

Date: Sun, 27 Sep 1998 12:39:19 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: DJ Delorie <dj AT delorie DOT com>
cc: djgpp-workers AT delorie DOT com
Subject: Re: snapshot 980907
In-Reply-To: <199809080049.UAA11536@delorie.com>
Message-ID: <Pine.SUN.3.91.980927123352.25393B-100000@is>
MIME-Version: 1.0

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;

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019