Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit277a47a

Browse files
committed
Accept and output '-Infinity' as well as 'Infinity', per long-ago
suggestion from Ross Reedstrom. Still needs work to make those symbolsconvert to actual IEEE infinities (on machines where such things exist).
1 parent1df27f9 commit277a47a

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

‎src/backend/utils/adt/float.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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)
199199
val=strtod(num,&endptr);
200200
if (*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
}
205212
else
206213
{
@@ -226,11 +233,15 @@ float4out(PG_FUNCTION_ARGS)
226233
{
227234
float4num=PG_GETARG_FLOAT4(0);
228235
char*ascii= (char*)palloc(MAXFLOATWIDTH+1);
236+
intinfflag;
229237

230238
if (isnan(num))
231239
PG_RETURN_CSTRING(strcpy(ascii,"NaN"));
232-
if (isinf(num))
240+
infflag=isinf(num);
241+
if (infflag>0)
233242
PG_RETURN_CSTRING(strcpy(ascii,"Infinity"));
243+
if (infflag<0)
244+
PG_RETURN_CSTRING(strcpy(ascii,"-Infinity"));
234245

235246
sprintf(ascii,"%.*g",FLT_DIG,num);
236247
PG_RETURN_CSTRING(ascii);
@@ -258,6 +269,8 @@ float8in(PG_FUNCTION_ARGS)
258269
val=NAN;
259270
elseif (strcasecmp(num,"Infinity")==0)
260271
val=HUGE_VAL;
272+
elseif (strcasecmp(num,"-Infinity")==0)
273+
val=-HUGE_VAL;
261274
else
262275
elog(ERROR,"Bad float8 input format '%s'",num);
263276
}
@@ -282,11 +295,15 @@ float8out(PG_FUNCTION_ARGS)
282295
{
283296
float8num=PG_GETARG_FLOAT8(0);
284297
char*ascii= (char*)palloc(MAXDOUBLEWIDTH+1);
298+
intinfflag;
285299

286300
if (isnan(num))
287301
PG_RETURN_CSTRING(strcpy(ascii,"NaN"));
288-
if (isinf(num))
302+
infflag=isinf(num);
303+
if (infflag>0)
289304
PG_RETURN_CSTRING(strcpy(ascii,"Infinity"));
305+
if (infflag<0)
306+
PG_RETURN_CSTRING(strcpy(ascii,"-Infinity"));
290307

291308
sprintf(ascii,"%.*g",DBL_DIG,num);
292309
PG_RETURN_CSTRING(ascii);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp