Re: float output precision questions

From: "Pedro M(dot) Ferreira" <pfrazao(at)ualg(dot)pt>
To: "Pedro M(dot) Ferreira" <pfrazao(at)ualg(dot)pt>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: float output precision questions
Date: 2002-10-31 13:47:35
Message-ID: 3DC13477.10208@ualg.pt
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Just one more note,

Maybe it makes sense that in the proposal below the parameter
EXTRA_DIGITS could be SIGNIFICANT_DIGITS with a default value of 15 and
maximum 18.
Its more 'documentable' and maybe easy to understand in general.

Pedro M. Ferreira wrote:

> Yes. I think there are several options.
> I checked the sprintf(ascii, "%A", num) output format and all the
> numbers that would fail because of DBL_DIG=15 are ok. After insertion on
> a table and conversion to double after a query, comparison a==b holds.
> AFAICT "%A" is system independent.
>
> I would (if I may) propose the following:
>
> Have two parameters, say DOUBLE_OUTPUT and EXTRA_DIGITS. DOUBLE_OUTPUT
> would select from decimal output or normalized output. EXTRA_DIGITS
> would add the required extra digits, from 0 (default) to 3, when output
> is decimal.
>
> EXTRA_DIGITS:
> in the range [0:3]. 0 as defualt.
>
> DOUBLE_OUTPUT:
>
> 'DECIMAL': sprintf(ascii, "%.*g", DBL_DIG+EXTRA_DIGITS, num); (default)
> 'NORMALIZED': sprintf(ascii, "%A", num);
>
> The same could be done for floats (float4).
>
> This way PG does not assume anything (DOUBLE_OUTPUT as 'NORMALIZED'), it
> does not hardwire 'inappropriate' assumptions about the number of
> significant digits in a double (default EXTRA_DIGITS=0), and it gives
> flexibility (EXTRA_DIGITS!=0) if needed.
> I think this is functional and reasonable.
>
> Regards,
> Pedro M. Ferreira
>
>>
>> regards, tom lane
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 2: you can get off all lists at once with the unregister command
>> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
>>
>>
>
>

--
----------------------------------------------------------------------
Pedro Miguel Frazao Fernandes Ferreira
Universidade do Algarve
Faculdade de Ciencias e Tecnologia
Campus de Gambelas
8000-117 Faro
Portugal
Tel./Fax: (+351) 289 800950 / 289 819403
http://w3.ualg.pt/~pfrazao

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Zeugswetter Andreas SB SD 2002-10-31 14:28:48 Re: float output precision questions
Previous Message Pedro M. Ferreira 2002-10-31 12:31:47 Re: float output precision questions