1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +03:00

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.
This commit is contained in:
Tom Lane
2001-10-13 23:32:34 +00:00
parent d1c6983899
commit e482dcb0a4
3 changed files with 53 additions and 9 deletions

View File

@ -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)
{