diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2001-06-02 20:18:30 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2001-06-02 20:18:30 +0000 |
commit | 277a47ad0febca0eeaf09b695639df7d93e3c628 (patch) | |
tree | 5b7fc347635fa5ff70f981e3fea2f38cfec0624d /src/backend/utils/adt/float.c | |
parent | 1df27f9a590b07492a5d1579f04b77e6700f11d7 (diff) | |
download | postgresql-277a47ad0febca0eeaf09b695639df7d93e3c628.tar.gz postgresql-277a47ad0febca0eeaf09b695639df7d93e3c628.zip |
Accept and output '-Infinity' as well as 'Infinity', per long-ago
suggestion from Ross Reedstrom. Still needs work to make those symbols
convert to actual IEEE infinities (on machines where such things exist).
Diffstat (limited to 'src/backend/utils/adt/float.c')
-rw-r--r-- | src/backend/utils/adt/float.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c index 42239cced02..da8ed2e29d4 100644 --- a/src/backend/utils/adt/float.c +++ b/src/backend/utils/adt/float.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.72 2001/06/02 17:12:12 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.73 2001/06/02 20:18:30 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -199,8 +199,15 @@ float4in(PG_FUNCTION_ARGS) val = strtod(num, &endptr); if (*endptr != '\0') { - /* Shouldn't we accept "NaN" or "Infinity" for float4? */ - elog(ERROR, "Bad float4 input format '%s'", num); + /* + * XXX we should accept "Infinity" and "-Infinity" too, but what + * are the correct values to assign? HUGE_VAL will provoke an + * error from CheckFloat4Val. + */ + if (strcasecmp(num, "NaN") == 0) + val = NAN; + else + elog(ERROR, "Bad float4 input format '%s'", num); } else { @@ -226,11 +233,15 @@ float4out(PG_FUNCTION_ARGS) { float4 num = PG_GETARG_FLOAT4(0); char *ascii = (char *) palloc(MAXFLOATWIDTH + 1); + int infflag; if (isnan(num)) PG_RETURN_CSTRING(strcpy(ascii, "NaN")); - if (isinf(num)) + infflag = isinf(num); + if (infflag > 0) PG_RETURN_CSTRING(strcpy(ascii, "Infinity")); + if (infflag < 0) + PG_RETURN_CSTRING(strcpy(ascii, "-Infinity")); sprintf(ascii, "%.*g", FLT_DIG, num); PG_RETURN_CSTRING(ascii); @@ -258,6 +269,8 @@ float8in(PG_FUNCTION_ARGS) val = NAN; else if (strcasecmp(num, "Infinity") == 0) val = HUGE_VAL; + else if (strcasecmp(num, "-Infinity") == 0) + val = -HUGE_VAL; else elog(ERROR, "Bad float8 input format '%s'", num); } @@ -282,11 +295,15 @@ float8out(PG_FUNCTION_ARGS) { float8 num = PG_GETARG_FLOAT8(0); char *ascii = (char *) palloc(MAXDOUBLEWIDTH + 1); + int infflag; if (isnan(num)) PG_RETURN_CSTRING(strcpy(ascii, "NaN")); - if (isinf(num)) + infflag = isinf(num); + if (infflag > 0) PG_RETURN_CSTRING(strcpy(ascii, "Infinity")); + if (infflag < 0) + PG_RETURN_CSTRING(strcpy(ascii, "-Infinity")); sprintf(ascii, "%.*g", DBL_DIG, num); PG_RETURN_CSTRING(ascii); |