delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/03/11:45:28

From: Andrew Gibson <andrew AT petrologic DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: printf 'g' conversion
Date: Tue, 03 Mar 1998 16:35:13 +0000
Message-ID: <34FC313E.E3730FF2@petrologic.co.uk>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 980302192029 DOT 1378C-100000 AT is>
NNTP-Posting-Host: petrologic.demon.co.uk
MIME-Version: 1.0
Lines: 91
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

>Thanks.  But could you please generate the patch with "diff -c3"?  It
>makes the patch process much more reliable.

*** doprnt.25x Sat Sep 14 02:20:28 1996
--- doprnt.c Fri Feb 27 11:10:26 1998
***************
*** 477,482 ****
--- 477,484 ----
    long double fract;
    int dotrim, expcnt, gformat;
    long double integer, tmp;
+   int doextradps=0;    /* Do extra decimal places if the precision
needs it */
+   int doingzero=0;     /* We're displaying 0.0 */
 
    if ((expcnt = isspeciall(number, startp)))
      return(expcnt);
***************
*** 524,529 ****
--- 526,538 ----
    }
    number = integer;
    fract = modfl(number, &integer);
+   /* If integer is zero then we need to look at where the sig figs are
*/
+   if (integer<1) {
+         /* If fract is zero the zero before the decimal point is a sig
fig */
+         if (fract==0.0) doingzero=1;
+         /* If fract is non-zero all sig figs are in fractional part */

+         else doextradps=1;
+   }
    /*
     * get integer portion of number; put into the end of the buffer;
the
     * .01 is added for modf(356.0 / 10, &integer) returning
.59999999...
***************
*** 660,668 ****
      break;
    case 'g':
    case 'G':
!     /* a precision of 0 is treated as a precision of 1. */
!     if (!prec)
!       ++prec;
      /*
       * ``The style used depends on the value converted; style e
       * will be used only if the exponent resulting from the
--- 669,683 ----
      break;
    case 'g':
    case 'G':
!     if (prec) {
!         /* If doing zero and precision is greater than 0 count the
!          * 0 before the decimal place */
!         if (doingzero) --prec;
!     }
!     else {
!         /* a precision of 0 is treated as precision of 1 unless doing
zero */
!         if (!doingzero) ++prec;
!     }
      /*
       * ``The style used depends on the value converted; style e
       * will be used only if the exponent resulting from the
***************
*** 707,713 ****
      {
        fract = modfl(fract * 10.0L, &tmp);
        *t++ = tochar((int)tmp);
!       prec--;
      }
      if (fract)
        startp = roundl(fract, (int *)NULL, startp, t - 1,
--- 722,734 ----
      {
        fract = modfl(fract * 10.0L, &tmp);
        *t++ = tochar((int)tmp);
!       /* If we're not adding 0s
!        * or we are but they're sig figs:
!        * decrement the precision */
!       if ((doextradps!=1) || ((int)tmp!=0)) {
!         doextradps=0;
!         prec--;
!       }
      }
      if (fract)
        startp = roundl(fract, (int *)NULL, startp, t - 1,
 

- Raw text -


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