🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

printf g format still broken under NeXTSTEP 3.0

#1487
From: eric
Date: Wed, 11 Nov 1992 01:22
52 lines
2374 bytes
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).

--
Eric Norum                     eric@skatter.usask.ca
Research Engineer              phone: (306) 966-6308
Accelerator Laboratory
University of Saskatchewan
Technical Details
Message-ID: <1992Nov11.012228.23372@access.usask.ca>
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!ames!elroy.jpl.nasa.gov!decwrl!access.usask.ca!news

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!ames!elroy.jpl.nasa.gov!decwrl!access.usask.ca!news
From: eric@skatter.usask.ca
Subject: printf g format still broken under NeXTSTEP 3.0 
Message-ID: <1992Nov11.012228.23372@access.usask.ca>
Sender: news@access.usask.ca (USENET News System)
Nntp-Posting-Host: skatter.usask.ca
Organization: University of Saskatchewan
Date: Wed, 11 Nov 1992 01:22:28 GMT
Lines: 52