Float output formatting options - Mailing list pgsql-hackers
From | Pedro M. Ferreira |
---|---|
Subject | Float output formatting options |
Date | |
Msg-id | 3DC67B1D.30108@ualg.pt Whole thread Raw |
Responses |
Re: Float output formatting options
|
List | pgsql-hackers |
Hi All, This relates to the recent discussion about floating point output format. The discussion was at a point where one parameter would be added to specify the number of extra digits used in fp output formatting. The parameter would have a 0 default value, a maximum of 2 and the minimum remained open for discussion. In a previous message I proposed that for double precision numbers a minimum value of -13 would be usefful. For single precision numbers this corresponds to a value of -4. I downloaded the PG sources and added two parameters (as PGC_USERSET): int extra_float4_digits, default 0, min -4, max 2 int extra_float8_digits, defualt 0, min -13, max 2 Compiled and tested for these functionalities. It is ok. The afected files are: src/backend/utils/adt/float.c src/backend/utils/misc/guc.c src/bin/psql/tab-complete.c src/backend/utils/misc/postgresql.conf.sample I used sources from Debian source package, postgresql_7.2.1-2woody2. Diff's produced with diff -u are enclosed as attachments. Can you comment on this (particularly the min values) ? Also, if we concluded that there is a need of 2 more digits, should'nt this be the default ? Best regards, Pedro M. Ferreira -- ---------------------------------------------------------------------- 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 --- old/postgresql-7.2.1/src/backend/utils/adt/float.c Tue Dec 11 02:02:12 2001 +++ postgresql-7.2.1/src/backend/utils/adt/float.c Mon Nov 4 10:32:33 2002 @@ -65,6 +65,12 @@ #include "utils/array.h" #include "utils/builtins.h" +/* + * Configuration options for float4 and float8 extra digits in output format + */ + +int extra_float4_digits; +int extra_float8_digits; #if !(NeXT && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_2) /* NS3.3 has conflicting declarations of these in <math.h> */ @@ -237,7 +243,7 @@ if (infflag < 0) PG_RETURN_CSTRING(strcpy(ascii, "-Infinity")); - sprintf(ascii, "%.*g", FLT_DIG, num); + sprintf(ascii, "%.*g", FLT_DIG+extra_float4_digits, num); PG_RETURN_CSTRING(ascii); } @@ -299,7 +305,7 @@ if (infflag < 0) PG_RETURN_CSTRING(strcpy(ascii, "-Infinity")); - sprintf(ascii, "%.*g", DBL_DIG, num); + sprintf(ascii, "%.*g", DBL_DIG+extra_float8_digits, num); PG_RETURN_CSTRING(ascii); } --- old/postgresql-7.2.1/src/backend/utils/misc/guc.c Tue Oct 30 05:38:56 2001 +++ postgresql-7.2.1/src/backend/utils/misc/guc.c Mon Nov 4 10:53:15 2002 @@ -49,6 +49,11 @@ extern int CommitSiblings; extern bool FixBTree; +/* For float4 and float8 extra digits in output format */ + +extern int extra_float4_digits; +extern int extra_float8_digits; + #ifdef ENABLE_SYSLOG extern char *Syslog_facility; extern char *Syslog_ident; @@ -502,6 +507,19 @@ "commit_siblings", PGC_USERSET, &CommitSiblings, 5, 1, 1000, NULL, NULL }, + + /* + * For float4 and float8 extra digits in output format + */ + { + "float4_extra_digits", PGC_USERSET, &extra_float4_digits, + 0, -4, 2, NULL, NULL + }, + + { + "float8_extra_digits", PGC_USERSET, &extra_float8_digits, + 0, -13, 2, NULL, NULL + }, { NULL, 0, NULL, 0, 0, 0, NULL, NULL --- old/postgresql-7.2.1/src/bin/psql/tab-complete.c Mon Nov 5 17:46:31 2001 +++ postgresql-7.2.1/src/bin/psql/tab-complete.c Mon Nov 4 11:16:01 2002 @@ -266,6 +266,9 @@ "default_transaction_isolation", + "float4_extra_digits", + "float8_extra_digits", + NULL }; --- old/postgresql-7.2.1/src/backend/utils/misc/postgresql.conf.sample Fri Jan 4 05:50:25 2002 +++ postgresql-7.2.1/src/backend/utils/misc/postgresql.conf.sample Mon Nov 4 11:02:04 2002 @@ -182,3 +182,9 @@ #password_encryption = false #sql_inheritance = true #transform_null_equals = false + +# +# floating point extra digits in output formatting +# +#extra_float4_digits = 0 #min -4, max 2 +#extra_float8_digits = 0 #min -13, max 2
pgsql-hackers by date: