www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/07/13/08:06:00

Date: Mon, 13 Jul 1998 08:05:44 -0400 (EDT)
Message-Id: <199807131205.IAA00842@delorie.com>
From: DJ Delorie <dj AT delorie DOT com>
To: eliz AT is DOT elta DOT co DOT il
CC: Kbwms AT aol DOT com, djgpp-workers AT delorie DOT com
In-reply-to: <Pine.SUN.3.91.980713105652.323B-100000@is> (message from Eli
Zaretskii on Mon, 13 Jul 1998 10:57:28 +0300 (IDT))
Subject: Re: printf "%g" format conversions

> Yes.  It could be argued that 0.012 is only 2 significant digits,
> whereas %.3g requests for 3.

Except that the ANSI spec, when talking about the f type (which the g
type mimics), uses the term "fraction digits" instead of "digits of
precision".  I think the intent is that %.3g yields 0.012, not 0.0123
(but it would have printed 1.23E-2).

However, this program:

	main()
	{
	  double x = 0.012341234;
	  printf("%.3e %.3f %.3g\n", x, x, x);
	}

Yeilds:

IRIX:	1.234e-02 0.012 0.0123
Linux:	1.234e-02 0.012 0.0123
SunOS4:	1.234e-02 0.012 0.0123
2.02:	1.234e-02 0.012 0.0123

So, I think we should leave it the way it is.

- Raw text -


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