8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.72 2001/06/02 17:12:12 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.73 2001/06/02 20:18:30 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -199,8 +199,15 @@ float4in(PG_FUNCTION_ARGS)
199
199
val = strtod (num , & endptr );
200
200
if (* endptr != '\0' )
201
201
{
202
- /* Shouldn't we accept "NaN" or "Infinity" for float4? */
203
- elog (ERROR , "Bad float4 input format '%s'" , num );
202
+ /*
203
+ * XXX we should accept "Infinity" and "-Infinity" too, but what
204
+ * are the correct values to assign? HUGE_VAL will provoke an
205
+ * error from CheckFloat4Val.
206
+ */
207
+ if (strcasecmp (num , "NaN" ) == 0 )
208
+ val = NAN ;
209
+ else
210
+ elog (ERROR , "Bad float4 input format '%s'" , num );
204
211
}
205
212
else
206
213
{
@@ -226,11 +233,15 @@ float4out(PG_FUNCTION_ARGS)
226
233
{
227
234
float4 num = PG_GETARG_FLOAT4 (0 );
228
235
char * ascii = (char * ) palloc (MAXFLOATWIDTH + 1 );
236
+ int infflag ;
229
237
230
238
if (isnan (num ))
231
239
PG_RETURN_CSTRING (strcpy (ascii , "NaN" ));
232
- if (isinf (num ))
240
+ infflag = isinf (num );
241
+ if (infflag > 0 )
233
242
PG_RETURN_CSTRING (strcpy (ascii , "Infinity" ));
243
+ if (infflag < 0 )
244
+ PG_RETURN_CSTRING (strcpy (ascii , "-Infinity" ));
234
245
235
246
sprintf (ascii , "%.*g" , FLT_DIG , num );
236
247
PG_RETURN_CSTRING (ascii );
@@ -258,6 +269,8 @@ float8in(PG_FUNCTION_ARGS)
258
269
val = NAN ;
259
270
else if (strcasecmp (num , "Infinity" ) == 0 )
260
271
val = HUGE_VAL ;
272
+ else if (strcasecmp (num , "-Infinity" ) == 0 )
273
+ val = - HUGE_VAL ;
261
274
else
262
275
elog (ERROR , "Bad float8 input format '%s'" , num );
263
276
}
@@ -282,11 +295,15 @@ float8out(PG_FUNCTION_ARGS)
282
295
{
283
296
float8 num = PG_GETARG_FLOAT8 (0 );
284
297
char * ascii = (char * ) palloc (MAXDOUBLEWIDTH + 1 );
298
+ int infflag ;
285
299
286
300
if (isnan (num ))
287
301
PG_RETURN_CSTRING (strcpy (ascii , "NaN" ));
288
- if (isinf (num ))
302
+ infflag = isinf (num );
303
+ if (infflag > 0 )
289
304
PG_RETURN_CSTRING (strcpy (ascii , "Infinity" ));
305
+ if (infflag < 0 )
306
+ PG_RETURN_CSTRING (strcpy (ascii , "-Infinity" ));
290
307
291
308
sprintf (ascii , "%.*g" , DBL_DIG , num );
292
309
PG_RETURN_CSTRING (ascii );
0 commit comments