aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/numeric.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-10-13 23:32:34 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-10-13 23:32:34 +0000
commite482dcb0a438dfa1fcb2cb792730c00db337a834 (patch)
tree6474f00c50a7ccd98906635bd4ceabe8a5f909ab /src/backend/utils/adt/numeric.c
parentd1c6983899df5b154c203c6f1ddf56914c0bbb30 (diff)
downloadpostgresql-e482dcb0a438dfa1fcb2cb792730c00db337a834.tar.gz
postgresql-e482dcb0a438dfa1fcb2cb792730c00db337a834.zip
Make selectivity routines cope gracefully with NaNs, infinities, and
NUMERIC values that are out of the range of 'double'. Per trouble report from Mike Quinn.
Diffstat (limited to 'src/backend/utils/adt/numeric.c')
-rw-r--r--src/backend/utils/adt/numeric.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 797586018d0..5160f690c1e 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -5,7 +5,7 @@
*
* 1998 Jan Wieck
*
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.44 2001/10/03 05:29:24 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/numeric.c,v 1.45 2001/10/13 23:32:33 tgl Exp $
*
* ----------
*/
@@ -1663,6 +1663,35 @@ numeric_float8(PG_FUNCTION_ARGS)
}
+/* Convert numeric to float8; if out of range, return +/- HUGE_VAL */
+Datum
+numeric_float8_no_overflow(PG_FUNCTION_ARGS)
+{
+ Numeric num = PG_GETARG_NUMERIC(0);
+ char *tmp;
+ double val;
+ char *endptr;
+
+ if (NUMERIC_IS_NAN(num))
+ PG_RETURN_FLOAT8(NAN);
+
+ tmp = DatumGetCString(DirectFunctionCall1(numeric_out,
+ NumericGetDatum(num)));
+
+ /* unlike float8in, we ignore ERANGE from strtod */
+ val = strtod(tmp, &endptr);
+ if (*endptr != '\0')
+ {
+ /* shouldn't happen ... */
+ elog(ERROR, "Bad float8 input format '%s'", tmp);
+ }
+
+ pfree(tmp);
+
+ PG_RETURN_FLOAT8(val);
+}
+
+
Datum
float4_numeric(PG_FUNCTION_ARGS)
{