Tom Lane writes:
 > Hiroshi Inoue <[EMAIL PROTECTED]> writes:
 > > Tom Lane wrote:
 > >> The defaults
 > >> would be "%.7g" and "%.17g" (or thereabouts, not sure what number of
 > >> digits we are currently using).
 > 
 > > Wouldn't changing current '%.6g','%.15g'(on many platforms)
 > > cause the regression test failure ? 
 > 
 > I didn't check my numbers.  If the current behavior is '%.6g','%.15g'
 > then we should stay with that as the default.
 > 
 > Hmm, on looking at the code, this might mean we need some configure
 > pushups to extract FLT_DIG and DBL_DIG and put those into the default
 > strings.  Do we support any platforms where these are not 6 & 15?

Please remind me what we are trying to do.  6 & 15 are values to
suppress trailing digits at the end of a number in a standard printf.
For example, 0.1 prints as 0.10000000000000001 at %.17g but as 0.1 at
%.16g.  However those shorter formats are less precise.  There are
several other doubles that will also print the same result.  A round
trip of printf/scanf will not generally preserve the number.

Printing for display purposes may not be adequate for dumping with a
view to restoring.  Are we talking about display or dump?

The ideal is to print just enough digits to be able to read the number
back.  There should be no redundant digits at the end.  Printf is
unable to do this by itself.  The reason is that the correct number of
decimal digits for a %.*g is a function of the number being printed.

There are algorithms to do the right thing but they can be expensive.
I play with some in a program at the URI below.  There is a minor typo
in the usage and a missing (optional) file.  I'll correct those when
the site allows uploads again.  The files' contents are currently
available at http://petef.8k.com/.
-- 
Pete Forman                 -./\.- Disclaimer: This post is originated
WesternGeco                   -./\.-  by myself and does not represent
[EMAIL PROTECTED]     -./\.-  opinion of Schlumberger, Baker
http://www.crosswinds.net/~petef  -./\.-  Hughes or their divisions.

Reply via email to