From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: printf 'g' conversion Date: Mon, 02 Mar 1998 08:40:42 -0800 Organization: Alcyone Systems Lines: 42 Message-ID: <34FAE10A.49F88C55@alcyone.com> References: NNTP-Posting-Host: newton.alcyone.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Eli Zaretskii wrote: > Sorry, I must be too dense today ;-). I *did* read the Standard > before posting. It says (in a fragment you didn't quote) that when > the `e' style would result in a sufficiently small exponent, `f' style > should be used. This is all okay, and DJGPP's libc does just that: it > prints a number like if you said "%11.9f". Where does it say this? In fact, it _shouldn't_ do this for the `e' (or `E'), because it means "I always want it in exponential notation no matter what." Or did you mean `g'? > What is unclear to me is whether using %11.9f for %9.9g is correct > when the former produces leading zeros, like in "0.012345679", since > these leading zeos are not, strictly speaking, significant digits. I > couldn't see anything in the Standard that clarifies this. Can you? Yeah, it's not entirely clear to me. The section on `f' says that "the number of digits after the decimal-point character is equal to the precision specification"; the section on `e' states, "... there is one digit before the decimal-point character (which is nonzero if the argument is nonzero) and the number of digits after it is equal to the precision ..."; and finally, the `g' format says, "... with the precision specifying the number of significant digits" (all quotes ANSI C 7.9.6.1). Note that the precision has subtly different meanings even for `e' and a `g' format -- "the number of digits after [the decimal point]" is _not_ even the same thing as "the number of significant digits." Yeah, I don't see anything that clarifies what the precision should be when carrying over a `g' conversion to an `f' one. I would presume that the assumption is that the precision should be the same, but it doesn't seem to say anything specific either way (and the explicit reference to "significant digits" might suggest otherwise). -- Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com Alcyone Systems / http://www.alcyone.com/max/ San Jose, California, United States / icbm://+37.20.07/-121.53.38 \ "I've got the fever for the / flavor of a cracker" / Ice Cube