Re: Float output formatting options - Mailing list pgsql-hackers

From Pedro M. Ferreira
Subject Re: Float output formatting options
Date
Msg-id 3DC7A75D.1030505@ualg.pt
Whole thread Raw
In response to Float output formatting options  ("Pedro M. Ferreira" <pfrazao@ualg.pt>)
Responses Re: Float output formatting options  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-hackers
Pedro M. Ferreira wrote:
> Tom Lane wrote:
>> Perhaps P_MAXLEN now needs to be (2*(DBL_DIG+2+7)+1), considering
>> that we'll allow extra_float_digits to be up to 2.  What's it used for?
>
> Yes. I guess so, because it is used in what I think is a memory
> allocation function. P_MAXLEN is only used twice:
<...>
>
> I will do the changes tomorrow and send in the appropriate diff's.

Ok. Its done now.
Only one file changed: src/backend/utils/adt/geo_ops.c

All the geometric types should now account for float_extra_digits on output.

A diff -u is attached.

Best reagards,
Pedro

> Regards,
> Pedro
>
>
> ---------------------------(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
--- old/postgresql-7.2.1/src/backend/utils/adt/geo_ops.c    Mon Nov  4 12:01:39 2002
+++ postgresql-7.2.1/src/backend/utils/adt/geo_ops.c    Tue Nov  5 10:47:56 2002
@@ -80,11 +80,11 @@
 #define RDELIM_C        '>'

 /* Maximum number of output digits printed */
-#define P_MAXDIG DBL_DIG
-#define P_MAXLEN (2*(P_MAXDIG+7)+1)
-
-static int    digits8 = P_MAXDIG;
+/* ...+2+7 : 2 accounts for extra_float_digits max value */
+#define P_MAXLEN (2*(DBL_DIG+2+7)+1)

+/* Extra digits in float output formatting (in float.c) */
+extern int extra_float_digits;

 /*
  * Geometric data types are composed of points.
@@ -139,7 +139,12 @@
 static int
 single_encode(float8 x, char *str)
 {
-    sprintf(str, "%.*g", digits8, x);
+    int    ndig = DBL_DIG + extra_float_digits;
+
+    if (ndig < 1)
+        ndig=1;
+
+    sprintf(str, "%.*g", ndig, x);
     return TRUE;
 }    /* single_encode() */

@@ -190,7 +195,12 @@
 static int
 pair_encode(float8 x, float8 y, char *str)
 {
-    sprintf(str, "%.*g,%.*g", digits8, x, digits8, y);
+    int    ndig = DBL_DIG + extra_float_digits;
+
+    if (ndig < 1)
+        ndig=1;
+
+    sprintf(str, "%.*g,%.*g", ndig, x, ndig, y);
     return TRUE;
 }

@@ -974,7 +984,7 @@
 #endif
 #ifdef GEODEBUG
         printf("line_construct_pts- line is neither vertical nor horizontal (diffs x=%.*g, y=%.*g\n",
-               digits8, (pt2->x - pt1->x), digits8, (pt2->y - pt1->y));
+               DBL_DIG, (pt2->x - pt1->x), DBL_DIG, (pt2->y - pt1->y));
 #endif
     }
 }
@@ -1180,8 +1190,8 @@

 #ifdef GEODEBUG
     printf("line_interpt- lines are A=%.*g, B=%.*g, C=%.*g, A=%.*g, B=%.*g, C=%.*g\n",
-           digits8, l1->A, digits8, l1->B, digits8, l1->C, digits8, l2->A, digits8, l2->B, digits8, l2->C);
-    printf("line_interpt- lines intersect at (%.*g,%.*g)\n", digits8, x, digits8, y);
+           DBL_DIG, l1->A, DBL_DIG, l1->B, DBL_DIG, l1->C, DBL_DIG, l2->A, DBL_DIG, l2->B, DBL_DIG, l2->C);
+    printf("line_interpt- lines intersect at (%.*g,%.*g)\n", DBL_DIG, x, DBL_DIG, y);
 #endif

     return result;
@@ -2390,14 +2400,14 @@
     p = line_interpt_internal(&tmp, line);
 #ifdef GEODEBUG
     printf("interpt_sl- segment is (%.*g %.*g) (%.*g %.*g)\n",
-           digits8, lseg->p[0].x, digits8, lseg->p[0].y, digits8, lseg->p[1].x, digits8, lseg->p[1].y);
+           DBL_DIG, lseg->p[0].x, DBL_DIG, lseg->p[0].y, DBL_DIG, lseg->p[1].x, DBL_DIG, lseg->p[1].y);
     printf("interpt_sl- segment becomes line A=%.*g B=%.*g C=%.*g\n",
-           digits8, tmp.A, digits8, tmp.B, digits8, tmp.C);
+           DBL_DIG, tmp.A, DBL_DIG, tmp.B, DBL_DIG, tmp.C);
 #endif
     if (PointerIsValid(p))
     {
 #ifdef GEODEBUG
-        printf("interpt_sl- intersection point is (%.*g %.*g)\n", digits8, p->x, digits8, p->y);
+        printf("interpt_sl- intersection point is (%.*g %.*g)\n", DBL_DIG, p->x, DBL_DIG, p->y);
 #endif
         if (on_ps_internal(p, lseg))
         {

pgsql-hackers by date:

Previous
From: Alessio Bragadini
Date:
Subject: Re: Request for supported platforms
Next
From: Satoshi Nagayasu
Date:
Subject: Re: protocol change in 7.4