Re: floating point representation - Mailing list pgsql-hackers

From Tom Lane
Subject Re: floating point representation
Date
Msg-id 13136.982350495@sss.pgh.pa.us
Whole thread Raw
In response to Re: floating point representation  (Peter Eisentraut <peter_e@gmx.net>)
Responses RE: floating point representation  ("Hiroshi Inoue" <Inoue@tpf.co.jp>)
List pgsql-hackers
Peter Eisentraut <peter_e@gmx.net> writes:
> The GNU C library now offers a %a (and %A) format that prints floating
> point numbers in a semi-internal form that is meant to be portable.  (I
> image this was done because of C99, but I'm speculating.)  It might be
> useful to offer this to preserve accurate data across dumps.

Here's what I find in the C99 draft:
      a,A     A double argument representing a (finite)  floating-              point    number    is   converted   in
the   style              [-]0xh.hhhhp�d, where there is one hexadecimal digit                          ^ � == "+/-" ...
tgl             (which  is  nonzero  if the argument is a normalized              floating-point number and is
otherwise unspecified)              before   the  decimal-point  character (219) and the              number of
hexadecimaldigits after it  is  equal  to              the  precision;  if  the  precision  is  missing and
FLT_RADIX is a power of 2,  then  the  precision  is              sufficient for an exact representation of the value;
           if the precision is missing and FLT_RADIX is  not  a              power  of  2,  then  the  precision is
sufficientto              distinguish (220) values of type double, except that              trailing zeros may be
omitted;if the  precision  is              zero  and  the  # flag is not specified, no decimal-              point
characterappears.   The  letters  abcdef  are              used  for  a conversion and the letters ABCDEF for A
    conversion.  The A conversion specifier  produces  a              number  with  X  and  P  instead  of  x  and p.
The             exponent always contains at  least  one  digit,  and              only  as  many more digits as
necessaryto represent              the decimal exponent of 2.  If the  value  is  zero,              the exponent is
zero.
              A double argument representing an infinity or NaN is              converted in the style  of  an  f  or
F conversion              specifier.
 
      ____________________
      219Binary  implementations  can choose the hexadecimal digit         to the  left  of  the  decimal-point
character so  that         subsequent digits align to nibble (4-bit) boundaries.
 
      220The precision p is sufficient to  distinguish  values  of         the source type if 16p-1>bn where b is
FLT_RADIXand n is         the number of base-b digits in  the  significand  of  the         source  type.  A smaller p
mightsuffice depending on the         implementation's scheme for determining the digit to  the         left of the
decimal-pointcharacter.
 
      7.19.6.1                   Library                  7.19.6.1
      314          Committee Draft  --  August 3, 1998   WG14/N843


So, it looks like C99-compliant libc implementations will have this,
but I'd hesitate to rely on it for pg_dump purposes; it would certainly
not be very portable for awhile yet.

Peter's idea of a SET variable to control float display format might
not be a bad idea, but what if anything should pg_dump do with it?
Maybe just crank the precision up a couple digits from the current
defaults?
        regards, tom lane


pgsql-hackers by date:

Previous
From: Erik Hofman
Date:
Subject: non blocking mode bug?
Next
From: "Martin A. Marques"
Date:
Subject: wish list for 7.2 (ALTER TABLE)