Re: float output precision questions
От | Pedro M. Ferreira |
---|---|
Тема | Re: float output precision questions |
Дата | |
Msg-id | 3DC13477.10208@ualg.pt обсуждение исходный текст |
Ответ на | Re: float output precision questions (Stephan Szabo <sszabo@megazone23.bigpanda.com>) |
Список | 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@postgresql.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
В списке pgsql-hackers по дате отправления: