need higher extra_float_digits value (3)

Lists: pgsql-bugs
From: Keh-Cheng Chu <kehcheng(at)sun(dot)Stanford(dot)EDU>
To: pgsql-bugs(at)postgresql(dot)org
Cc: Keh-Cheng Chu <kehcheng(at)sun(dot)Stanford(dot)EDU>
Subject: need higher extra_float_digits value (3)
Date: 2009-09-09 18:51:52
Message-ID: 20090909185152.GA7893@kehcheng.Stanford.EDU
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

I have applications that require IEEE floating-point data
to remain unchanged to the last bit after a dump/restore
cycle. Currently on all our linux systems, pg_dump uses
8 significant figures (FLT_DIG + 2) to dump 32-bit reals
and 17 significant figures (DBL_DIG + 2) to dump 64-bit
doubles, where FLT_DIG and DBL_DIG are defined in float.h
as 6 and 15, respectively, and 2 is the maximum allowed value
for extra_float_digits.

While 17 decimal digits are sufficient to guarantee the
complete recovery of all 64-bit double values, some 32-bit
reals actually require NINE significant figures. For example,
the binary real 0x3dcccd70 is converted using 8 significant
figures to 0.10000122, which if converted back to binary will
become 0x3dcccd71. A general proof for why 9 significant
figures are required for 32-bit reals (and 17 for 64-bit
doubles) is in Theorem 15 of David Goldberg's "What Every
Computer Scientist Should Know About Floating-Point Arithmetic",
which is available on the web and as an appendix to Sun's
Numerical Computation Guide.

I have been running a locally modified postgresql server with
extra_float_digits' upper limit increased by one to 3 and a
modified pg_dump which sets extra_float_digits to 3; I have
verified that the modification does what I need and it does
not seem to have any side effect other than providing one
more significant figure than needed for double precision
binary to decimal conversion. I would like to ask the
postgresql development team to consider it for a future
release.

Thanks,

Keh-Cheng Chu
Solar Physics Group, Hansen Experimental Physics Lab
Stanford University


P.S. I run slony with extra_float_digits set to 3 in
(my locally modified) postgresql.conf in order to
get around the same precision problem. It would be
nice if slony would do something similar to pg_dump
and enable the extra digits by default; I will bring
that up with slony developers if this modification is
accepted.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Keh-Cheng Chu <kehcheng(at)solar2(dot)Stanford(dot)EDU>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: need higher extra_float_digits value (3)
Date: 2009-09-09 22:04:29
Message-ID: 8398.1252533869@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Keh-Cheng Chu <kehcheng(at)solar2(dot)Stanford(dot)EDU> writes:
> While 17 decimal digits are sufficient to guarantee the
> complete recovery of all 64-bit double values, some 32-bit
> reals actually require NINE significant figures.

Hm, annoying. Seems like we could do one of two things:

1. Increase the max extra_float_digits value to 3 and have pg_dump use
that.

2. Split extra_float_digits into two settings so that float4 and float8
can use different settings.

Offhand the only argument I can see for #2 is that #1 might bloat dump
files unnecessarily --- but it's not likely to be significant on a
percentage basis.

We'd also need to check the code to be sure it's leaving room for the
extra digit in all cases, though I doubt there's really any problem.

Comments?

regards, tom lane


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Keh-Cheng Chu <kehcheng(at)solar2(dot)stanford(dot)edu>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: need higher extra_float_digits value (3)
Date: 2009-09-10 01:18:50
Message-ID: 603c8f070909091818n2bf92d75j6d41d3e1c313c245@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On Wed, Sep 9, 2009 at 6:04 PM, Tom Lane<tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Keh-Cheng Chu <kehcheng(at)solar2(dot)Stanford(dot)EDU> writes:
>> While 17 decimal digits are sufficient to guarantee the
>> complete recovery of all 64-bit double values, some 32-bit
>> reals actually require NINE significant figures.
>
> Hm, annoying.  Seems like we could do one of two things:
>
> 1. Increase the max extra_float_digits value to 3 and have pg_dump use
> that.
>
> 2. Split extra_float_digits into two settings so that float4 and float8
> can use different settings.
>
> Offhand the only argument I can see for #2 is that #1 might bloat dump
> files unnecessarily --- but it's not likely to be significant on a
> percentage basis.
>
> We'd also need to check the code to be sure it's leaving room for the
> extra digit in all cases, though I doubt there's really any problem.

(2) seems like overkill to me, FWIW.

...Robert


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Keh-Cheng Chu <kehcheng(at)solar2(dot)Stanford(dot)EDU>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: need higher extra_float_digits value (3)
Date: 2009-09-11 19:17:55
Message-ID: 9030.1252696675@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Keh-Cheng Chu <kehcheng(at)solar2(dot)Stanford(dot)EDU> writes:
> I have been running a locally modified postgresql server with
> extra_float_digits' upper limit increased by one to 3 and a
> modified pg_dump which sets extra_float_digits to 3; I have
> verified that the modification does what I need and it does
> not seem to have any side effect other than providing one
> more significant figure than needed for double precision
> binary to decimal conversion. I would like to ask the
> postgresql development team to consider it for a future
> release.

Committed for 8.5.

regards, tom lane