aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/float.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-11-08 17:37:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-11-08 17:37:52 +0000
commitd2c744aa56aca7fe756a156a8e2109aaa676e54f (patch)
treec60eaa7b71536a84e20e883da6b28d7ad60fc229 /src/backend/utils/adt/float.c
parentfef731d1c40e0cfd98d8a3cb724f696c9abe6f7d (diff)
downloadpostgresql-d2c744aa56aca7fe756a156a8e2109aaa676e54f.tar.gz
postgresql-d2c744aa56aca7fe756a156a8e2109aaa676e54f.zip
Add extra_float_digits GUC parameter to allow adjustment of displayed
precision for float4, float8, and geometric types. Set it in pg_dump so that float data can be dumped/reloaded exactly (at least on platforms where the float I/O support is properly implemented). Initial patch by Pedro Ferreira, some additional work by Tom Lane.
Diffstat (limited to 'src/backend/utils/adt/float.c')
-rw-r--r--src/backend/utils/adt/float.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c
index fa34e105c15..c0acc554b8e 100644
--- a/src/backend/utils/adt/float.c
+++ b/src/backend/utils/adt/float.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.82 2002/10/19 02:08:17 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.83 2002/11/08 17:37:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -94,9 +94,6 @@ extern double rint(double x);
#endif /* NeXT check */
-static void CheckFloat4Val(double val);
-static void CheckFloat8Val(double val);
-
#ifndef M_PI
/* from my RH5.2 gcc math.h file - thomas 2000-04-03 */
#define M_PI 3.14159265358979323846
@@ -113,8 +110,6 @@ static void CheckFloat8Val(double val);
#define SHRT_MIN (-32768)
#endif
-#define FORMAT 'g' /* use "g" output format as standard
- * format */
/* not sure what the following should be, but better to make it over-sufficient */
#define MAXFLOATWIDTH 64
#define MAXDOUBLEWIDTH 128
@@ -128,6 +123,14 @@ static void CheckFloat8Val(double val);
#define FLOAT8_MIN DBL_MIN
+/* Configurable GUC parameter */
+int extra_float_digits = 0; /* Added to DBL_DIG or FLT_DIG */
+
+
+static void CheckFloat4Val(double val);
+static void CheckFloat8Val(double val);
+
+
/*
* check to see if a float4 val is outside of
* the FLOAT4_MIN, FLOAT4_MAX bounds.
@@ -228,6 +231,7 @@ float4out(PG_FUNCTION_ARGS)
float4 num = PG_GETARG_FLOAT4(0);
char *ascii = (char *) palloc(MAXFLOATWIDTH + 1);
int infflag;
+ int ndig;
if (isnan(num))
PG_RETURN_CSTRING(strcpy(ascii, "NaN"));
@@ -237,7 +241,12 @@ float4out(PG_FUNCTION_ARGS)
if (infflag < 0)
PG_RETURN_CSTRING(strcpy(ascii, "-Infinity"));
- sprintf(ascii, "%.*g", FLT_DIG, num);
+ ndig = FLT_DIG + extra_float_digits;
+ if (ndig < 1)
+ ndig = 1;
+
+ sprintf(ascii, "%.*g", ndig, num);
+
PG_RETURN_CSTRING(ascii);
}
@@ -290,6 +299,7 @@ float8out(PG_FUNCTION_ARGS)
float8 num = PG_GETARG_FLOAT8(0);
char *ascii = (char *) palloc(MAXDOUBLEWIDTH + 1);
int infflag;
+ int ndig;
if (isnan(num))
PG_RETURN_CSTRING(strcpy(ascii, "NaN"));
@@ -299,7 +309,12 @@ float8out(PG_FUNCTION_ARGS)
if (infflag < 0)
PG_RETURN_CSTRING(strcpy(ascii, "-Infinity"));
- sprintf(ascii, "%.*g", DBL_DIG, num);
+ ndig = DBL_DIG + extra_float_digits;
+ if (ndig < 1)
+ ndig = 1;
+
+ sprintf(ascii, "%.*g", ndig, num);
+
PG_RETURN_CSTRING(ascii);
}