**Submitter:** Project Editor (Larry Jones)

**Submission Date:** 2000-04-24

**Source:** Chris Torek

**Reference Document:** N/A

**Version:** 1.5

**Date:** 2007-09-07

**Subject:** ` %g`,

**Summary**

7.19.6.1 (and similarly in 7.24.2.1):

g,G- A
argument representing a floating-point number is converted in styledoubleorf(or in styleeorFin the case of aEconversion specifier), with the precision specifying the number of significant digits. If the precision is zero, it is taken as 1. The style used depends on the value converted; styleG(ore) is used only if the exponent resulting from such a conversion is less than -4 or greater than or equal to the precision. Trailing zeros are removed from the fractional portion of the result unless theEflag is specified; a decimal-point character appears only if it is followed by a digit.#A

argument representing an infinity or NaN is converted in the style of andoubleorfconversion specifier.F

Assuming "significant digits" is being used in the scientific-notation sense. This means that, for instance, the number "12.34" has four significant digits. So does "0.1234", and so does "0.001234". A value like "1.200" also has four significant digits, counting trailing zeros, but not leading zeros.

Now, ` %g` normally suppresses trailing zeros
(as described above), so applying

must produce "1.200", four significant digits.printf("%#.4g\n", 1.2);

The problem occurs when we go to print the value 0.0. No matter how many digits we tack on the end, we still have no significant digits. So what should:

print? "0.0000" has no significant digits. "0.0" has no significant digits. "0.000000000000000000000000000000000000000" still has no significant digits. Which of these, if any, is correct output? Which of these isprintf("%#.4g\n", 0.0);

The only way this wording makes any sense is if "significant digits" means something else entirely, but then what does it mean?

**Committee Discussion** (for history only)

There seemed to be some uncertainty about whether (for the
` %.4g` example) the exponent would be

Some Committee members wondered whether the exponent would
be ` 1` or

If there is no implementation representation of ZERO, but rather a very small number. In this case, we generally thought that this was a user problem, that they could not rely on a true ZERO having a representation, in which case, they would need to place their own checks for what approximations were acceptable as ZERO and print a literal instead.

Some pathological cases were checked, and appeared to work correctly.

NOTE: In discussion, the original bullets were:

- if X < -4 or X >= P, the conversion is with style e (or E) and precision P - 1
- otherwise the conversion is with style f (or F) and precision P - ( X + 1 )

- if P > X >= -4, the conversion is with style f (or F) and precision P - ( X + 1 )
- otherwise the conversion is with style e (or E) and precision P - 1

During discussion, as it was considered to be the more pure form.

**Technical Corrigendum**

Change 7.19.6.1 paragraph 8 and 7.24.2.1 paragraph 8 to:

g,G- A
argument representing a floating-point number is converted in styledoubleorf(or in styleeorFin the case of aEconversion specifier), depending on the value converted and the precision. LetGequal the precision if non-zero, 6 if the precision is omitted, or 1 if the precision is zero. Then, if a conversion with stylePwould have an exponent ofE:X

- if
, the conversion is with styleP > X >= -4(orf) and precisionF.P - (X + 1)- otherwise the conversion is with style
(ore) and precisionE.P - 1Finally, unless theflag is used, any trailing zeroes are removed from the fractional portion of the result and the decimal-point character is removed if there is no fractional portion remaining.#