cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2008/04/23/12:40:15

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Recipient: djgpp-workers AT delorie DOT com
X-Authenticated: #27081556
X-Provags-ID: V01U2FsdGVkX1/xIs8YKYPx5tGsPJtU1qi/WObYbxoAs8+I2yWhVt
1nXVuVVZvm1XeP
From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
To: djgpp-workers AT delorie DOT com
Subject: Re: Printing signed zeros and nans
Date: Wed, 23 Apr 2008 18:24:17 +0200
User-Agent: KMail/1.9.5
MIME-Version: 1.0
Message-Id: <200804231824.19329.juan.guerrero@gmx.de>
X-Y-GMX-Trusted: 0
Reply-To: djgpp-workers AT delorie DOT com

The reported issue concerns signed zero and signed nan.  Signed infinity is
not affected.  I have checked in the following patch.

Regards,
Juan M. Guerrero



Index: src/libc/ansi/stdio/doprnt.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/doprnt.c,v
retrieving revision 1.21
diff -p -U3 -r1.21 doprnt.c
--- src/libc/ansi/stdio/doprnt.c	14 Mar 2008 22:26:54 -0000	1.21
+++ src/libc/ansi/stdio/doprnt.c	23 Apr 2008 16:24:32 -0000
@@ -41,7 +41,9 @@ static char decimal = '.';
 		flags&CHARINT ? (char basetype)va_arg(argp, int) : \
 		(basetype)va_arg(argp, int)
 
-static int nan_p = 0;
+#define IS_ZERO(x)  ((x).ldt.exponent == 0x0U && (x).ldt.mantissah == 0x0UL && (x).ldt.mantissal == 0x0UL)
+#define IS_NAN(x)   ((x).ldt.exponent == 0x7FFFU && ((x).ldt.mantissah & 0x7FFFFFFFUL || (x).ldt.mantissal))
+
 
 static __inline__ int todigit(char c)
 {
@@ -275,6 +277,7 @@ _doprnt(const char *fmt0, va_list argp, 
        * softsign avoids negative 0 if _double is < 0 and
        * no significant digits will be shown
        */
+      softsign = 0;
       if (_ldouble < 0)
       {
 	softsign = '-';
@@ -288,10 +291,13 @@ _doprnt(const char *fmt0, va_list argp, 
 	ip.ld = _ldouble;
 
 	if (ip.ldt.sign)
+	{
 	  neg_ldouble = 1;
+	  if (IS_ZERO(ip) || IS_NAN(ip))
+	    softsign = '-';
+	}
 	else
 	  neg_ldouble = 0;
-	softsign = 0;
       }
       /*
        * cvt may have to round up past the "start" of the
@@ -307,9 +313,8 @@ _doprnt(const char *fmt0, va_list argp, 
        * 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_p == -1)))
+      if (softsign || (sign == '+' && neg_ldouble))
 	sign = '-';
-      nan_p = 0;
       t = *buf ? buf : buf + 1;
       goto pforw;
     case 'n':
@@ -916,7 +921,6 @@ isspeciall(long double d, char *bufp)
 
   ip.ldouble = d;
 
-  nan_p = 0;  /* don't assume the static is 0 (emacs) */
 
   /* Unnormals: the MSB of mantissa is non-zero, but the exponent is
      not zero either.  */
@@ -930,11 +934,7 @@ isspeciall(long double d, char *bufp)
   if (ip.ip.exp != 0x7fff)
     return(0);
   if ((ip.ip.manh & 0x7fffffff) || ip.ip.manl)
-  {
     strcpy(bufp, "NaN");
-    nan_p = ip.ip.sign ? -1 : 1; /* kludge: we don't need the sign, it's
-				    not nice, but it should work */
-  }
   else
     (void)strcpy(bufp, "Inf");
   return(3);

- Raw text -


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