🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #1503

Re: printf g format still broken under NeXTSTEP 3.0

#1503
From: Ronald C. Antony
Date: Wed, 11 Nov 1992 09:59
80 lines
3822 bytes
In article <1992Nov11.012228.23372@access.usask.ca> eric@skatter.usask.ca writes:
>I reported this bug in December 1989, and when NeXTSTEP 2.0 came out,
>and when NeXTSTEP 2.1 arrived, and now that NeXTSTEP 3.0 has arrived ...
>IT STILL ISN'T FIXED!!!!!
>
>Here's an example program:
>
>#include <stdio.h>
>int
>main (int argc, char **argv)
>{
>	int i, d;
>	double x, y;
>
>	y = 3.141592654;
>	for (i = 0, d = 1 ; i < 5 ; i++, d *= 10) {
>		x = y / d;
>		printf ("%12g %12.1g %12.2g %12.3g %12.4g\n", x, x, x, x, x);
>	}
>	return (0);
>}
>
>Here's what *should* print (according to the ANSI standard).  And it *does*
>print this on our SUN 4.1.2, and HP-UX V8, systems:
>     3.14159            3          3.1         3.14        3.142
>    0.314159          0.3         0.31        0.314       0.3142
>   0.0314159         0.03        0.031       0.0314      0.03142
>  0.00314159        0.003       0.0031      0.00314     0.003142
> 0.000314159       0.0003      0.00031     0.000314    0.0003142
>
>And here's what the NeXT produces:
>    3.141593          3.1         3.14        3.142       3.1416
>    0.314159          0.3         0.31        0.314       0.3142
>    0.031416            0         0.03        0.031       0.0314
>    0.003142            0            0        0.003       0.0031
>    0.000314            0            0            0       0.0003
>
>For the umpteenth time, NeXT:
>1. The precision specifier for %g format is supposed to set the number of
>   significant digits in the printed number.
>
>2. Non-zero digits to the left of the decimal point *do* count towards
>   the number of significant digits (see the first line of the tables).
>
>3. Leading zeroes do not count towards the number of significant digits,
>   even when they are to the right of the decimal point (see the last
>   three lines of the tables).

Well, not to protect NeXT in regards to sleeping over important bug
reports (sometimes I also wonder how they set the priorities, altough
certainly nobody could claim they are otherwise lazy), I still wonder
if they are not right. Maybe there are just two opinions what ANSI-C
is supposed to do.

The C-Bible "The C Programming Language" by K+R, 2nd edition, ANSI-C
states the following on page 244:

f	double; decimal notation of the form [-]mmm.ddd, where the
	d's is specified by the precision. The default precision is 6;
	a precision of ) suppresses the decimal point.

e,E	double; decimal notation of the form [-]m.dddddd e[+-]xx or
	[-]mdddddd E[+-]xx, where the number of d's is specified by
	the precision. The default precision is 6; a precision of 0
	suppresses the decimal point.
g,G	double; %e or %E is used if the exponent is less than -4 or
	greater than or equal to the precision; otherwise %f is used.
	Trailing zeros and a trailing decimal point are not printed.


Now if they got it right, NeXT got it right. If K+R got it wrong,
well, then NeXT should correct the bug and tell Prentice Hall to
correct their bug as well.

Ronald

------------------------------------------------------------------------------
"The reasonable man adapts himself to the world; the unreasonable one persists
in trying to adapt the world to himself. Therefore all progress depends on the
unreasonable man."   G.B. Shaw   |  rca@cs.brown.edu or antony@browncog.bitnet
Technical Details
Message-ID: <1992Nov11.095957.22979@cs.brown.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!brunix!brunix!rca
References: <1992Nov11.012228.23372@access.usask.ca>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!brunix!brunix!rca
From: rca@cs.brown.edu (Ronald C. Antony)
Subject: Re: printf g format still broken under NeXTSTEP 3.0 
Message-ID: <1992Nov11.095957.22979@cs.brown.edu>
Sender: news@cs.brown.edu
Organization: Brown University Department of Computer Science
References: <1992Nov11.012228.23372@access.usask.ca>
Date: Wed, 11 Nov 1992 09:59:57 GMT
Lines: 80