www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/07/12/13:07:17

Date: Sun, 12 Jul 1998 20:05:59 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: DJ Delorie <dj AT delorie DOT com>, Andrew Gibson <andrew AT petrologic DOT co DOT uk>
cc: djgpp-workers AT delorie DOT com, Kbwms AT aol DOT com
Subject: printf "%g" format conversions
Message-ID: <Pine.SUN.3.91.980712200300.27114i-100000@is>
MIME-Version: 1.0

The change in cvtl (on doprnt.c) was applied incorrectly, which made
it work erratically, and cause nasty crashes with "%.1g".  A patch
is attached.

However, I'm unsure about whether this change is justified.  What it
does is to cause e.g. printf ("%.3g", 0.01234) print "0.0123" instead
of "0.012", as in v2.01.  I wonder whether this is correct?  The ANSI
standard says that, under certain conditions (which hold in this
example), %g behaves as %f would.  But "%.3f" will print 0.012 here,
so aren't we violating the standard?

*** src/libc/ansi/stdio/doprnt.c~0	Sun Jun 28 23:58:02 1998
--- src/libc/ansi/stdio/doprnt.c	Sat Jul 11 12:27:30 1998
*************** cvtl(long double number, int prec, int f
*** 527,532 ****
--- 527,533 ----
        *p-- = '0';
    }
    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 */
*************** cvtl(long double number, int prec, int f
*** 534,540 ****
          /* If fract is non-zero all sig figs are in fractional part */
          else doextradps=1;
    }
-   fract = modfl(number, &integer);
    /*
     * get integer portion of number; put into the end of the buffer; the
     * .01 is added for modf(356.0 / 10, &integer) returning .59999999...
--- 535,540 ----

- Raw text -


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