Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4987ca2

Browse files
committed
This is a patch to make cube output work like double precision output
with regard to the extra_float_digits setting. Since builtins.h was already included, I just deleted the extern statement (and accompaning comments). Bruno Wolff III
1 parent 349d529 commit 4987ca2

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

contrib/cube/cube.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,16 @@ cube_out(NDBOX * cube)
121121
bool equal = true;
122122
int dim = cube->dim;
123123
int i;
124+
int ndig;
124125

125126
initStringInfo(&buf);
126127

128+
/*
129+
* Get the number of digits to display.
130+
*/
131+
ndig = DBL_DIG + extra_float_digits;
132+
if (ndig < 1) ndig = 1;
133+
127134
/*
128135
* while printing the first (LL) corner, check if it is equal to the
129136
* second one
@@ -133,7 +140,7 @@ cube_out(NDBOX * cube)
133140
{
134141
if (i > 0)
135142
appendStringInfo(&buf, ", ");
136-
appendStringInfo(&buf, "%.16g", cube->x[i]);
143+
appendStringInfo(&buf, "%.*g", ndig, cube->x[i]);
137144
if (cube->x[i] != cube->x[i + dim])
138145
equal = false;
139146
}
@@ -146,7 +153,7 @@ cube_out(NDBOX * cube)
146153
{
147154
if (i > 0)
148155
appendStringInfo(&buf, ", ");
149-
appendStringInfo(&buf, "%.16g", cube->x[i + dim]);
156+
appendStringInfo(&buf, "%.*g", ndig, cube->x[i + dim]);
150157
}
151158
appendStringInfoChar(&buf, ')');
152159
}

contrib/cube/expected/cube.out

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,39 +145,39 @@ SELECT '-1e-700'::cube AS cube;
145145
(1 row)
146146

147147
SELECT '1234567890123456'::cube AS cube;
148-
cube
149-
--------------------
150-
(1234567890123456)
148+
cube
149+
------------------------
150+
(1.23456789012346e+15)
151151
(1 row)
152152

153153
SELECT '+1234567890123456'::cube AS cube;
154-
cube
155-
--------------------
156-
(1234567890123456)
154+
cube
155+
------------------------
156+
(1.23456789012346e+15)
157157
(1 row)
158158

159159
SELECT '-1234567890123456'::cube AS cube;
160-
cube
161-
---------------------
162-
(-1234567890123456)
160+
cube
161+
-------------------------
162+
(-1.23456789012346e+15)
163163
(1 row)
164164

165165
SELECT '.1234567890123456'::cube AS cube;
166-
cube
167-
----------------------
168-
(0.1234567890123456)
166+
cube
167+
---------------------
168+
(0.123456789012346)
169169
(1 row)
170170

171171
SELECT '+.1234567890123456'::cube AS cube;
172-
cube
173-
----------------------
174-
(0.1234567890123456)
172+
cube
173+
---------------------
174+
(0.123456789012346)
175175
(1 row)
176176

177177
SELECT '-.1234567890123456'::cube AS cube;
178-
cube
179-
-----------------------
180-
(-0.1234567890123456)
178+
cube
179+
----------------------
180+
(-0.123456789012346)
181181
(1 row)
182182

183183
-- simple lists (points)

0 commit comments

Comments
 (0)