www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/10/04/07:47:15

Date: Sun, 4 Oct 1998 13:24:41 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: DJ Delorie <dj AT delorie DOT com>
cc: djgpp-workers AT delorie DOT com
Subject: Patch for _doprnt to print -0.000 and -NaN
Message-ID: <Pine.SUN.3.91.981004132224.1863u-100000@is>
MIME-Version: 1.0

The following patch for doprnt.c corrects the problem with printing
signs of 0.000 and NaN.  After this patch, if you request the sign in the 
format specifier (with the `+' flag), you will see the true sign of both 
0.000 numbers and NaNs.

*** src/libc/ansi/stdio/doprnt.c~0	Sun Jul 12 15:30:42 1998
--- src/libc/ansi/stdio/doprnt.c	Fri Oct  2 12:48:52 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,275 ----
        *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, and we also print a sign for a NaN.  In
!        * other words, "%+f" might print -0.000000, +NaN and -NaN.
!        */
!       if (softsign || (sign == '+' && (neg_ldouble || nan == -1)))
  	sign = '-';
        nan = 0;
        t = *buf ? buf : buf + 1;
*************** isspeciall(long double d, char *bufp)
*** 857,864 ****
    if ((ip->manh & 0x7fffffff) || ip->manl)
    {
      strcpy(bufp, "NaN");
!     nan = 1;			/* kludge: we don't need the sign,  it's not nice
! 				   but it should work */
    }
    else
      (void)strcpy(bufp, "Inf");
--- 868,875 ----
    if ((ip->manh & 0x7fffffff) || ip->manl)
    {
      strcpy(bufp, "NaN");
!     nan = ip->sign ? -1 : 1; /* kludge: we don't need the sign,  it's not nice
! 				but it should work */
    }
    else
      (void)strcpy(bufp, "Inf");
*** src/docs/kb/wc202.t~1	Tue Sep 29 11:51:12 1998
--- src/docs/kb/wc202.txi	Fri Oct  2 12:59:26 1998
*************** will be disabled inside blocks that call
*** 459,461 ****
--- 459,473 ----
  @cindex SIGALRM
  @cindex SIGPROF
  @cindex profiling
+ 
+ The functions of the @code{printf} family now always print a negative
+ sign for a negative floating-point argument, even when the conversion
+ generated no significant digits (i.e. only zeros are printed), if the
+ format specifier requests an explicit sign, like in "%+f".  A special
+ NaN value will also be printed with a sign in these cases (e.g. try
+ printing @code{-nanf()}).
+ @findex printf
+ @findex fprintf
+ @findex sprintf
+ @findex _doprnt
+ @findex nanf

- Raw text -


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