88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.72 2001/06/0217:12:12 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.73 2001/06/0220:18:30 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -199,8 +199,15 @@ float4in(PG_FUNCTION_ARGS)
199199val = strtod (num ,& endptr );
200200if (* endptr != '\0' )
201201{
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 );
204211}
205212else
206213{
@@ -226,11 +233,15 @@ float4out(PG_FUNCTION_ARGS)
226233{
227234float4 num = PG_GETARG_FLOAT4 (0 );
228235char * ascii = (char * )palloc (MAXFLOATWIDTH + 1 );
236+ int infflag ;
229237
230238if (isnan (num ))
231239PG_RETURN_CSTRING (strcpy (ascii ,"NaN" ));
232- if (isinf (num ))
240+ infflag = isinf (num );
241+ if (infflag > 0 )
233242PG_RETURN_CSTRING (strcpy (ascii ,"Infinity" ));
243+ if (infflag < 0 )
244+ PG_RETURN_CSTRING (strcpy (ascii ,"-Infinity" ));
234245
235246sprintf (ascii ,"%.*g" ,FLT_DIG ,num );
236247PG_RETURN_CSTRING (ascii );
@@ -258,6 +269,8 @@ float8in(PG_FUNCTION_ARGS)
258269val = NAN ;
259270else if (strcasecmp (num ,"Infinity" )== 0 )
260271val = HUGE_VAL ;
272+ else if (strcasecmp (num ,"-Infinity" )== 0 )
273+ val = - HUGE_VAL ;
261274else
262275elog (ERROR ,"Bad float8 input format '%s'" ,num );
263276}
@@ -282,11 +295,15 @@ float8out(PG_FUNCTION_ARGS)
282295{
283296float8 num = PG_GETARG_FLOAT8 (0 );
284297char * ascii = (char * )palloc (MAXDOUBLEWIDTH + 1 );
298+ int infflag ;
285299
286300if (isnan (num ))
287301PG_RETURN_CSTRING (strcpy (ascii ,"NaN" ));
288- if (isinf (num ))
302+ infflag = isinf (num );
303+ if (infflag > 0 )
289304PG_RETURN_CSTRING (strcpy (ascii ,"Infinity" ));
305+ if (infflag < 0 )
306+ PG_RETURN_CSTRING (strcpy (ascii ,"-Infinity" ));
290307
291308sprintf (ascii ,"%.*g" ,DBL_DIG ,num );
292309PG_RETURN_CSTRING (ascii );