🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2253

Question about printf %g format

#2253
From: Eric Norum
Date: Tue, 08 Jan 1991 03:18
24 lines
1198 bytes
I have a question about printf's `%g' format.  Specifically, what should

	#include <stdio.h>
	main ()
	{
		printf ("%.3g\n", 0.0001234);
	}

print?

It seems to me that leading zero's shouldn't count as significant when
printf chooses to use `f' format ..... so `0.000123' should be printed.

The HP-UX and Sun 4.1  machines here agree with me, but some other
systems choose to print `0'. (!!!)

I hope the latter behaviour is wrong, but when I read K&R II page 244 I'm
not sure.  Is the `correct' behaviour documented somewhere?

-- 
Eric Norum
Dept. of Electrical Engineering      eric@ee.ualberta.ca
University of Alberta
Edmonton, Canada.                   phone: (403) 492-4626
Technical Details
Message-ID: <1991Jan8.031801.28996@ee.ualberta.ca>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!zephyr.ens.tek.com!uw-beaver!ubc-cs!alberta!edson!news

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!zephyr.ens.tek.com!uw-beaver!ubc-cs!alberta!edson!news
From: eric@ee.ualberta.ca (Eric Norum)
Newsgroups: comp.std.c
Subject: Question about printf %g format
Keywords: printf, floating point
Message-ID: <1991Jan8.031801.28996@ee.ualberta.ca>
Date: 8 Jan 91 03:18:01 GMT
Sender: news@ee.ualberta.ca
Reply-To: eric@ee.ualberta.ca (Eric Norum)
Organization: University of Alberta Electrical Engineering
Lines: 24