Re: floating point representation - Mailing list pgsql-hackers

From Pete Forman
Subject Re: floating point representation
Date
Msg-id 14994.15246.973584.711036@kryten.bedford.waii.com
Whole thread Raw
In response to Re: floating point representation  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: floating point representation  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane writes:> Hiroshi Inoue <Inoue@tpf.co.jp> 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'(onmany platforms)> > cause the regression test failure ? > > I didn't check my numbers.  If the current
behavioris '%.6g','%.15g'> then we should stay with that as the default.> > Hmm, on looking at the code, this might
meanwe need some configure> pushups to extract FLT_DIG and DBL_DIG and put those into the default> strings.  Do we
supportany 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
pete.forman@westerngeco.com     -./\.-  opinion of Schlumberger, Baker
http://www.crosswinds.net/~petef  -./\.-  Hughes or their divisions.


pgsql-hackers by date:

Previous
From: Justin Clift
Date:
Subject: Re: beta5 ...
Next
From: Hiroshi Inoue
Date:
Subject: Re: Re: [ADMIN] v7.1b4 bad performance